This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Compiling GCC With a C++ Compiler (g++)
- From: Gabriel Dos Reis <gdr at cs dot tamu dot edu>
- To: "Dave Korn" <dk at artimi dot com>
- Cc: "'Geoffrey Keating'" <geoffk at apple dot com>,"'Joseph S. Myers'" <jsm at polyomino dot org dot uk>,"'Zack Weinberg'" <zack at codesourcery dot com>,"'Ranjit Mathew'" <rmathew at gmail dot com>, <gcc at gcc dot gnu dot org>,"'Andreas Schwab'" <schwab at suse dot de>
- Date: 14 Oct 2004 07:42:56 -0500
- Subject: Re: Compiling GCC With a C++ Compiler (g++)
- Organization: Texas A&M University, Department of Computer Science
- References: <NUTMEGD3zCParqjPikM00000488@NUTMEG.CAM.ARTIMI.COM>
"Dave Korn" <dk@artimi.com> writes:
| [ 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.
Yep.
| What about this function: is it valid, conformant C?
|
| void fubar (const char *x)
| {
| *(char *)x = '?';
| }
It is valid C and C++, if only if the object pointed to by x is const.
| 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)?
If you remove the argument about malloc(), I agree.
| Does this still make sense? It's making my mind
| boggle in several directions at once.
I think there is a hole in the argument about allocating object
with malloc(). The key is to understand what the effective type of
the object is.
-- Gaby