macro_x madness heads up
Andreas Ericsson
ae at op5.se
Fri Nov 5 13:01:09 CET 2010
On 11/05/2010 12:12 PM, Ton Voon wrote:
>
> On 5 Nov 2010, at 09:45, Andreas Ericsson wrote:
>
>> Using this completely untested program, what output do you get?
>>
>> #include<sys/types.h>
>> #include<stdio.h>
>> #include<unistd.h>
>> #define psize(type) printf("sizeof(" #type ") = %d\n", sizeof(type))
>>
>> int main(int argc, char **argv)
>> {
>> psize(time_t);
>> psize(__darwin_suseconds_t);
>> psize(int);
>> psize(long);
>> psize(off_t);
>> psize(void *);
>> psize(long long);
>> return 0;
>> }
>
> I get:
>
> $ ./a.out
> sizeof(time_t) = 4
> sizeof(__darwin_suseconds_t) = 4
> sizeof(int) = 4
> sizeof(long) = 4
> sizeof(off_t) = 8
> sizeof(void *) = 4
> sizeof(long long) = 8
>
> macbook 10.5, 32bit.
>
Basically, size_t == int == long gcc should just shut the fsck up
about those.
time_t == __darwin_suseconds_t. There's no portable way to print
time_t except casting the argument to unsigned long, so I'll do
that.
The only thing that differs between your system and mine is off_t
not being same size as (void *), which is extremely odd indeed.
It really should be the same as a 'long' on all systems (long long
is C99-ish, so we can't really use that).
size_t gets its printf() format spec from C99 as well. The portable
way of printing it without warnings is to cast it to unsigned long
and use %lu in the format string.
Yuck and yuck for such types tbh.
--
Andreas Ericsson andreas.ericsson at op5.se
OP5 AB www.op5.se
Tel: +46 8-230225 Fax: +46 8-230231
Considering the successes of the wars on alcohol, poverty, drugs and
terror, I think we should give some serious thought to declaring war
on peace.
------------------------------------------------------------------------------
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a
Billion" shares his insights and actions to help propel your
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
More information about the Developers
mailing list