From -710734139821836582
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,bc2d9b2f726f122d
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1994-06-27 04:14:45 PST
Newsgroups: comp.std.c++
Path: bga.com!news.sprintlink.net!hookup!yeshua.marcam.com!MathWorks.Com!europa.eng.gtefsd.com!howland.reston.ans.net!pipex!sunic!trane.uninett.no!eunet.no!nuug!EU.net!uunet!world!miket
From: miket@world.std.com (Michael Trachtman)
Subject: Re: #if sizeof( int ) == 2
Message-ID: <Cs1z13.35v@world.std.com>
Organization: High Level Designs
X-Newsreader: TIN [version 1.2 PL2]
References: <BWH.94Jun24202306@kato.prl.ufl.edu> <2uk8lr$hkg@explorer.clark.net> <BWH.94Jun26232515@kato.prl.ufl.edu>
Date: Mon, 27 Jun 1994 11:10:15 GMT
Lines: 41

Brian Hook (bwh@kato.prl.ufl.edu) wrote:
: In article <2uk8lr$hkg@explorer.clark.net> thutt@clark.net (Taylor Hutt) writes:

: >   At runtime, you can: assert(sizeof(int) == 2);
: >   This will get caught immediately.

: But this won't allow me to do conditional compilation, which is what I
: want.  An alternative is to use limits.h, which I'll try.

How about ??

if (sizeof(int) == 2) {
    do_thing();
} else if (sizeof(int) == 4) {
    do_something_else();
} else {
    im_totally_confused();
}

This is not quite conditional compilation. But it sure is close.

And..  (since the expression (sizeof(int) == 2) is a compile
time constant)
it is possible that some compilers may optimize this at compile
time and eliminate the if-else-test at runtime.
I.e. on a 16 bit machine, the resulting code (with a good optimizer) may be:

    do_thing();

and on a 32 bit machine, the result code (with a good optimizer) may be:

    do_something_else().

And on a 64 bit machine it would be:

    im_totally_confused();

You'd have to play with your compiler and the optimization switches to
see.

Michael T.


