On 11/25/2011 3:06 PM, James Kuyper wrote:
> On 11/25/2011 06:01 AM, Jean-Michel Hautbois wrote:
>> On Nov 24, 6:00�pm, James Kuyper<jameskuy...@verizon.net> wrote:
>>> On 11/24/2011 04:06 AM, Philipp Klaus Krause wrote:
> ...
>>>> Am 23.11.2011 21:41, schrieb James Kuyper:
> ...
>>>>> The C standard does not mandate the existence of any feature that would
>
> Note the use of the word "not".
>
>>>>> produce such output at compile time. The only output that normally
>>>>> appears at compile time and is mandated by the C standard is diagnostic
>>>>> messages, the text of which is not specified by the standard, nor under
>>>>> the control of the developer - with the exception of the #error
>>>>> directive. However, the #error directive is executed during phase 4;
>>>>> sizeof expressions cannot be evaluated until phase 7, so the value of
>>>>> such expressions cannot appear in #error output.
>
> Note the use of the word "cannot".
>
>>>> Well, sizeof, unless applied to a variable-length array, yields an
>>>> integer constant. Which AFAIK, can be used e.g. as array bound. That's
>>>> how I understood the OP's "would like, at compile time ideally, [�], to
>>>> know the footprint in memory" requirement.
>>>
>>> I agree that, when VLAs are not involved, the compiler has sufficient
>>> information to produce the result that he wants; I'm just letting him
>>> know the C standard doesn't mandate support for any feature that would
>
> Note the use of the word "doesn't".
>
>>> have the desired effect.
> ...
>> Taking both of your remarks into account, I am understanding that
>> #error with sizeof can produce the output I want at compile time.
>
> I curious how you reached that conclusion, because what I said was
> almost precisely the opposite. Well, not exactly - the standard doesn't
> mandate support for any features that could be counted on to produce the
> result that you want at compile time, but neither does it prohibit them.
I of course goofed up in my previous post and James (thanks!) corrected
me alright.
What I meant (and what works) is to manually create a bunch of const
size_t objects initialized with sizes of your structures, using sizeof,
offsetof and other goodies as necessary, as long as they yield integer
constant expression (6.6p6). You can compile them in conditionally
(#ifdef MYDEBUG) and print them out or inspect in the debugger at runtime.
If I am guessing it right that you want to ensure that some size is
equal to another: that "some size" can be coded as sizeof(another).
--
Ark
|