Re: detecting 64-bitness inside a program
From: Larry Doolittle (ldoolitt_at_recycle.lbl.gov)
Date: 09/12/03
- Next message: David Schwartz: "Re: c simple error"
- Previous message: Randy Howard: "Re: detecting 64-bitness inside a program"
- In reply to: Peter Ammon: "Re: detecting 64-bitness inside a program"
- Next in thread: Valentin Nechayev: "Re: detecting 64-bitness inside a program"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 12 Sep 2003 02:46:03 +0000 (UTC)
In article <bjr68u$fi1$1@news.apple.com>, Peter Ammon wrote:
>
> The semantics of the preprocessor were chosen so that the preprocessor
> could be a fairly simple program external to the C compiler proper. If
> the preprocessor were required to compute sizeof(someExpression), then
> it would have to have to include the better part of a C parser.
Completely correct.
>> One of the well-known properties of C is that the size of every
>> data type is fixed and known at compile time.
>
> Compilation proper typically occurs after preprocessing.
Also correct. The workaround, to figure out sizeof at compile time
(very important if the compiler is really a cross-compiler) is to
test compile a C file like this:
int check_sizeof(int i) { switch (i) {
case 4: return 1;
case sizeof(unsigned long): return 2;
} return 0; }
If sizeof(unsigned long)==4, such a compiliation is required by the standard
to fail. Automating this check (in a *nix environment) is a trivial
exercise. This is the kind of work that is properly done in an autoconf
setting, although autoconf-2.13 (at least) does not have it built in.
Of course, this method is not original to me. I believe it got discussed
to death on comp.lang.c many years ago. While it might not work on every
compiler, because the error goes undetected, those compilers are broken
(according to the standard), a bug report should be filed, and you should
consider buying/downloading a non-broken replacement. Certainly both
gcc-2.9x and gcc-3.x can be expected to work.
- Larry
- Next message: David Schwartz: "Re: c simple error"
- Previous message: Randy Howard: "Re: detecting 64-bitness inside a program"
- In reply to: Peter Ammon: "Re: detecting 64-bitness inside a program"
- Next in thread: Valentin Nechayev: "Re: detecting 64-bitness inside a program"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|