|
Boost-Build : |
Subject: Re: [Boost-build] Python port development
From: Artyom (artyomtnk_at_[hidden])
Date: 2010-07-09 15:24:56
> >> I can confirm this. Yesterday I did just that. And used it for
>configuration of
>
> >> wxWidgets with Boost.Build, for defining SIZEOF_WCHAR_T macro
>appropriately (other sizeofs weren't required for now).
> >> Very funny coincidence that this talk and my implementation happened at
>nearly
>
> >> the same, I must say ;-)
> >>
> >
> > How did you do this? Using negative array size trick?
> >
>
> I would also be interested in knowing exactly how you did this.
> The way I would handle it would be to build a program
> that prints the size and read the output.
That is exactly the way it should not be done, and that is exactly the reason
you
should give it to build system:
Why it can't be done using printing the sizeof: It does not work when you cross
compile,
for example I compile on Windows Intel to Linux ARM because compiling on arm is
very slow. You can't run
the compilation test because it is ARM executable, and if you do compile and run
native (and not target)
you can actually get wrong result.
So the correct solution (that is done in autotools for years and only recently
in CMake)
is following.
How can we check for example if sizeof(wchar_t) >= 4?
char test[sizeof(wchar_t)*2 - 7]
If sizeof(wchar_t) == 4 then 4*2-7 == 1 and the code is legal and compilation
succeeds,
If sizeof(wchar_t) == 2 then 2*2 - 7 == -3 and this code is not legal and
compilation fails.
It is very tricky to implement this correctly. This is why it shouldn't be done
by users
as most of them would use the solution you had suggested, and it is wrong.
Just to make it clear, even CMake had done this right only recently, before this
it was implemented
incorrectly. This solution was discovered very long time ago by autotools.
Artyom
P.S.: BTW sizeof(wchar_t)==2 only if you work on Windows, rest platforms have
sizeof(wchar_t)==4
Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk