Afficher un message
Vieux 02/02/2008, 22h17   #6
Keith Thompson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Integer multiplication truncation

Mamluk Caliph <mamluk.caliph@gmail.com> writes:
[...]
> By the way, I tried defining my own types and thought I could do
> something as follows:
>
> #if sizeof(int)==4
> typedef int myInt32_t;
> #endif
>
> This results in a compilation error `missing binary operator before
> token "("`, why is that? I thought sizof was just a macro.

[...]

No, sizeof is a built-in unary operator. (Its symbol happens to be a
keyword rather than a punctuation symbol.) The preprocessor doesn't
the "sizeof" or "int" keywords, so you can't use "sizeof(int)" in a
"#if" directive.

You can use the macros defined in <limits.h> in preprocessor
directives, though, and since these specify the ranges that the types
can represent rather than the sizes of their representations, they
might be more appropriate.

--
Keith Thompson (The_Other_Keith) <kst-u@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
  Réponse avec citation
 
Page generated in 0,05489 seconds with 9 queries