On Wed, 24 Oct 2007 12:03:38 -0700
"Andrew Pinski" <[EMAIL PROTECTED]> wrote:

> On 10/24/07, John Gateley <[EMAIL PROTECTED]> wrote:
> > The situation is this: I have a lot of code that uses a string class
> > which takes advantage of the pun: the string class has only the
> > one data member, which means you can do things like printf("%s", obj)
> > and have the right thing happen (using a different compiler, of course).
> > Is there any way to use this useful pun with g++?
> 
> This is way undefined code really.  The class is a non POD since you
> have a private member.  And the C++ standard says it is undefined what
> happens when you pass a non-POD for a varable arguments function (the
> reasoning is due to virtual functions and knowning the full size of
> the struct).
> 
> Also using %s with anything but a char* is undefined behavior anyways
> (even if it is a struct that only contains a char* since the ABI could
> say they are passed differently).

I don't think it is undefined code. The class has no virtual functions,
and the variable argument function doesn't need to know the full size
of the struct, since it is not using it as a String object, it is using
it as a char * pointer (which is what gets passed).

I'm not familiar with "ABI". But perhaps this has something to do
with my other question: is the illegal instruction that gets executed
a "real" illegal instruction, caused by g++ doing something different
that I expected with the String object as an argument? Or is the illegal
instruction just a "place marker" that is generated because I passed
a non-POD as an argument?

Thanks for your reply...

j
-- 
John Gateley <[EMAIL PROTECTED]>

Reply via email to