Compiling GCC With a C++ Compiler (g++)

Geoffrey Keating geoffk@apple.com
Thu Oct 14 20:19:00 GMT 2004


On 14/10/2004, at 5:33 AM, Dave Korn wrote:

>
> [ Phil Edwards snecked from Cc: line in accordance with his wish to 
> escape
> "this eternal thread"! ]
>
>> -----Original Message-----
>> From: Geoffrey Keating
>> Sent: 13 October 2004 20:42
>
>> On 13/10/2004, at 8:23 AM, Dave Korn wrote:
>
>>>   Huh?  Are you saying that in:
>>>
>>> typedef struct { const char x } AA;
>>>
>>> AA *py1, py2;
>>> AA y1 = { z };
>>>
>>>   py1 = malloc (sizeof *py2);
>>>   py2 = &y1;
>>>
>>> it is valid to say
>>>
>>>   *(char *)(&py1->x) = '?';
>>>
>>> but not valid to say
>>>
>>>   *(char *)(&py2->x) = '?';
>>
>> Yes, that sounds right.
>
>
>   Wow, we really seem to me to be entering the realm of the bizarre 
> here.
> What about this function: is it valid, conformant C?
>
> void fubar (const char *x)
> {
>     *(char *)x = '?';
> }

It can be part of a conforming program, yes.

>   Is it not implicit from what you've just told me that the answer to 
> the
> question of whether or not that function is valid conformant C depends 
> on
> whether the value of the pointer you pass into it was originally 
> derived
> from a call to malloc (valid) or by taking the address-of a local or 
> static
> variable (not valid)?  Does this still make sense?  It's making my mind
> boggle in several directions at once.

Yes, it matters what value 'x' has.  For instance, consider

int main(void)
{
   fubar(NULL);
   return 0;
}

Obviously that program is not conforming, whether or not 'x' is const.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2408 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20041014/5413926d/attachment.p7s>


More information about the Gcc mailing list