This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: cannot pass objects of non-POD type


On 10/24/07, John Gateley <gateley@jriver.com> 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).

-- Pinski


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]