wxMac 2.8/Xcode 3.1.4 - wxLog*() function throw EXC_BAD_INSTRUCTION.

3 views
Skip to first unread message

Martín Sebastián Wain

unread,
Nov 3, 2009, 4:23:20 PM11/3/09
to wx-u...@googlegroups.com
Hi, I'm completly lost here. I'm getting errors on wxLog*() calls.
I'm still a newbie with Mac, but apparently this has something to do with "..."
parameters.
I thought that wxLog* functions used a bunch of template definitions (with 1, 2, 3...
etc parameters)  to avoid varadic "..." parameters' weird behaviour when passing
wxStrings, and such.

The compiler throws a warning that says:
warning: cannot pass objects of non-POD type 'struct std::basic_string
<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >'
through '...'; call will abort at runtime

Do you have any ideas?
Thanks in advance.

--
-Martín
Two bananas and milk [ http://www.tbam.com.ar ]

Mark Gollahon

unread,
Nov 3, 2009, 4:43:38 PM11/3/09
to wx-u...@googlegroups.com
It is not the wxLog* function that is the problem - it is the fact you
are trying to pass a std::string to it. Try calling your string's
"c_str()" function.

Martín Sebastián Wain

unread,
Nov 3, 2009, 4:49:35 PM11/3/09
to wx-u...@googlegroups.com
Damn, I have it like that in a million places =(
What's weird is that in MSVC++ works with strings. I found Xcode to be a bit bitchy
when it comes to resolving casting operators.

Thanks!

Andreas Mohr

unread,
Nov 3, 2009, 4:57:03 PM11/3/09
to wx-u...@googlegroups.com
Hi,

On Tue, Nov 03, 2009 at 06:49:35PM -0300, Martín Sebastián Wain wrote:
> Damn, I have it like that in a million places =(
> What's weird is that in MSVC++ works with strings. I found Xcode to be a bit
> bitchy
> when it comes to resolving casting operators.

"works" is relative. Make it run on 64bit and watch it explode. :)
But yeah, on a MSVC environment people don't tend to have such trouble
probably since all they care about is 32bit x86 only anyway...

Andreas Mohr

David Connet

unread,
Nov 3, 2009, 5:07:33 PM11/3/09
to wx-u...@googlegroups.com
--- On Tue, 11/3/09, Andreas Mohr <an...@lisas.de> wrote:
> On Tue, Nov 03, 2009 at 06:49:35PM -0300, Martín Sebastián Wain wrote:
> > Damn, I have it like that in a million places =(
> > What's weird is that in MSVC++ works with strings. I
> > found Xcode to be a bit
> > bitchy
> > when it comes to resolving casting operators.

Variadic functions don't apply cast operators. Hence the reason you should NEVER pass non-pod data. (CStrings are currently written in such a way that they "happen" to work)

>
> "works" is relative. Make it run on 64bit and watch it explode. :)

Heck, the next release of the compiler could cause fireworks too! That's the fun of undefined behavior. It's undefined! (just cause it looks like it works now, doesn't mean it will tomorrow) (and I really wish MS had that non-pod type warning - it's extremely useful!)

Dave

Martín Sebastián Wain

unread,
Nov 3, 2009, 5:32:17 PM11/3/09
to wx-u...@googlegroups.com
I know that, but I thought I saw wxWidgets using the multi-param template approach.
I.e.:
template <typename T1>  void function(T1 p1);
template <typename T1, typename T2>  void function(T1 p1, T2, p2);
template <typename T1, typename T2, typename T3>  void function(T1 p1, T2, p2, T3 p3);
template <typename T1, typename T2, typename T3, typename T4>  void function(T1 p1, T2, p2, T3 p3, T4 p4);
etc.

Then applying a specific-defined stringifier templated function to turn the parameters to use them, avoiding the varadic parameter issue altoghether. I.e.:

template <typename T1>  stringify(T1 p1);
template <> wxString stringify(int p) { return wxString::fromInt(p); }
template <> wxString stringify(std::wstring p) { return p.c_str(); }
etc.

Best regards

Vadim Zeitlin

unread,
Nov 3, 2009, 8:36:14 PM11/3/09
to wx-u...@googlegroups.com
On Tue, 3 Nov 2009 18:23:20 -0300 Martín Sebastián Wain <nitra...@gmail.com> wrote:

MSW> Hi, I'm completly lost here. I'm getting errors on wxLog*() calls.
MSW> I'm still a newbie with Mac, but apparently this has something to do with
MSW> "..."
MSW> parameters.
MSW> I thought that wxLog* functions used a bunch of template definitions (with
MSW> 1, 2, 3... etc parameters) to avoid varadic "..." parameters' weird
MSW> behaviour when passing wxStrings, and such.

This is true for the trunk (i.e. 2.9) but not for 2.8.

Also, the behaviour is not weird -- it's undefined. This (unfortunately
IMO) means that it might even work and Microsoft went to special trouble in
their CString implementation to make it work when passed by value to a
vararg function (apparently this was simpler than teaching C++ to all MFC
users).

MSW> The compiler throws a warning that says:
MSW> warning: cannot pass objects of non-POD type 'struct std::basic_string
MSW> <wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >'
MSW> through '...'; call will abort at runtime

This warning seems admirably clear to me. You need .c_str() when passing
wxStrings to vararg functions (but you don't need it with any previously
vararg functions in 2.9 because they're not vararg any more).

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Martín Sebastián Wain

unread,
Nov 4, 2009, 2:32:19 AM11/4/09
to wx-u...@googlegroups.com
"apparently this was simpler than teaching C++ to all MFC users"
Hehehe.

Well, then that's the reason! I knew I'd seen template code when messing
around with wx sources!
I used 2.9 for the Windows build (which worked) and 2.8 for Mac.
I had problems getting a fresh svn copy (connection  problems) so I went
back to the "safe" 2.8 pack and forgot about it.

By weird I meant undefined, as in "works here, explodes there"
The warning is clear enough but I was misguided by the fact that
it compiled without any whining at MSVC (v2008 is a lot more strict than v6)
and I was completly sure that I had seen log functions using templates
and not varadic params (and I wasn't mistaken except for the version!)

I will install the trunk version tomorrow.
Thanks Vadz!
Reply all
Reply to author
Forward
0 new messages