Re: Getting the size of type in the preprocessor.
Re: Getting the size of type in the preprocessor.
- Subject: Re: Getting the size of type in the preprocessor.
- From: Tim Little <email@hidden>
- Date: Tue, 2 Sep 2008 23:01:35 -0500
Using that trick I now have everything sorted. I can test for C99 compatibility and use that preferentially, otherwise I test for MSVC, and then fall back to a set of assumptions that I can effectively assert on at compile time if the sizes are not exactly what i expect.
Thanks all.
Tim
On Sep 2, 2008, at 8:47 PM, Chris Suter wrote: On Wed, Sep 3, 2008 at 11:31 AM, Steve Checkoway <email@hidden> wrote: On Tue, Sep 02, 2008 at 07:35:49PM -0500, Tim Little wrote: > Thanks, I had completely forgotten those existed now. MS doesn't > support them in VS, but they have alternatives that are easy to use. I think the thing to do is use the standard types and for compilers which don't support standards (basically just VS, right?) define the types yourself.
On a semi-related note, you can perform compile time checks on sizes of types by doing this:
#define CHECK3(x, line) typedef char check ## line[(x) ? 1 : -1]; #define CHECK2(x, line) CHECK3(x, line) #define CHECK(x) CHECK2(x, __LINE__)
CHECK(sizeof(int) == 4)
You'll get a compiler error if that ever wasn't true.
-- Chris
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden