CFanatic

Go Back   CFanatic > Programming > C Programming > Advance C


  #1  
Old 09-30-2006, 06:23 AM
Amigo Amigo is offline
Junior Member
 
Join Date: Sep 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Amigo is on a distinguished road
| More
Preprocessor and sizeof()

Hello all!

I started working on an embedded project a few ago on Freescale 16-bit micro with an IAR toolset. Running PolySpace for the project code highlighted amongst other things a peculiar construct in one of the compiler's header files. Here's the code snippet:

#ifndef __SIZE_T_TYPE__
#if sizeof((char*)0 - (char*)0) <= sizeof(int)
#define __SIZE_T_TYPE__ unsigned int
#else
#define __SIZE_T_TYPE__ unsigned long
#endif
#endif

I was very suspicious about this construct in the first place, but coming from a compiler vendor baffled me even more. Although I kind of understand what the author wanted, the combination of sizeof and pre-processing is bound to not comply with the ANSI C specification.

My question is: have you ever encountered such a construct in a file delivered by a tool vendor? It definitely "works", in that the compiler does not throw errors or warnings. But because this code goes into a safety-related project I need to understand exactly what's happening in the code and why. Any thoughts appreciated.

Cheers,
Romeo

PS: I was dumped in the project team just last week, so I did not have time to look through the whole of the project (documentation is
"standard", i.e. poor)
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
sizeof for a class coderzone C Programming 2 06-05-2007 10:29 PM

 

Follow CFanatic on Twitter
CFanatic Search
Custom Search

Advertisement

Go4Expert's Job Board
Powered by

Go4Expert Newsletter
Enter your Name and Email Address below and Click Subscribe.

Subscriber Counter

Not planning to subscribe yet, browse Go4Expert's Newsletter Archive

All times are GMT -5. The time now is 05:58 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Looking for work in C, C++, C#? Sign up at Elance and search over 30,000 Freelancing jobs today.