Boost logo

Boost-Build :

Subject: Re: [Boost-build] Python port development
From: Artyom (artyomtnk_at_[hidden])
Date: 2010-07-09 16:08:06

> From: Steven Watanabe <watanabesj_at_[hidden]>
> To: Boost.Build developer's and user's list <boost-build_at_[hidden]>
> Sent: Fri, July 9, 2010 10:56:32 PM
> Subject: Re: [Boost-build] Python port development
> > How can we check for example if sizeof(wchar_t) >= 4?
> >
> There are many ways to trigger a compiler error in C++.
> In C, yeah, a negative array size is probably the easiest.
> > 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.
> How is this particularly tricky? I can see that it would get tedious
> is the size is not known to be one of a few possibility (thus requiring
> a binary search), but it seems like this is rather the obvious solution
> when running a compiled program isn't possible.

It is not tricky when you know the solution :-).
But as you can see neither your nor Gevorg, did this right.

BTW: why do you need there *2? In order to get negative value as some
     compilers accept 0 as valid array size.

Also it is simple to check one specific case sizeof >= KnownValue,
but lets say you want to know that is the size of some structure,
with unknown expected size.

So you need to write a loop that compiles this for several cases and then run it
increasing each time
twice and then run binary search... Not so simple at all.



Boost-Build list run by bdawes at, david.abrahams at, gregod at, cpdaniel at, john at