Re: #define vs. const

From: Chris Theis (Christian.Theis_at_nospam.cern.ch)
Date: 09/19/04


Date: Sun, 19 Sep 2004 21:08:56 +0200


"Ioannis Vranos" <ivr@guesswh.at.grad.com> schrieb im Newsbeitrag
news:cikdiv$1h2o$1@ulysses.noc.ntua.gr...
> Chris Theis wrote:
[SNIP]
>
> In most compilers inclusion guards can be replaced with #pragma
> directives. Like
>
> #pragma once
>

Yes, that's true but still compiler dependent.

>
>
> > or of some more nifty uses
> > like in compile time asserts with more informative error messages. I
simply
> > donŽt know how youŽd achieve it without a macro.
> >
> > template <bool x> struct StaticAssert {
> > StaticAssert(...);
> > };
> > template <> struct StaticAssert<false>{};
> > #define COMPILE_ASSERT( Expr, Msg ) \
> > { \
> > class ERROR_##Msg {}; \
> > (void)sizeof( StaticAssert<(Expr) != 0>(( ERROR_##Msg()))); \
> > }
>
>
> With an array of pointers to functions or objects may be?
>

Hmm, could you please elaborate on that. I don't quite see how to gain
informative error messages from compile-time (!) asserts with pointers to
functions or objects. I'd be really interested how to do this, so I'd
appreciate an example.

Best regards
Chris



Relevant Pages

  • Re: Correspondence between headers and macros
    ... So Norcroft doesn't support "#pragma once". ... Supported by some, but not all compilers. ... CPP supports two more ways of indicating that a header file should ...
    (comp.lang.c)
  • Re: C is too old? opinions?
    ... You insisted that this pragma is supported by many compilers, ... I cannot find any mention of it in the documentation for my current gcc ... If they support if, it is undocumented and probably deprecated. ... OS platforms and all the mainstream compilers used this pragma I know I ...
    (comp.lang.c)
  • RE: pragma section
    ... The compilers available with eVC4.0 do not support that pragma. ... be using Windows CE 5.0 with Platform Builder or Visual Studio .NET 2005 ... > int j = 0; ...
    (microsoft.public.windowsce.app.development)
  • Re: if !defined and #pragma once
    ... Microsoft added the #pragma once ... construct, but since code had to be compiled with older compilers, the older ... include-guards had to remain in place. ... Starting with VS.NET, this older support was dropped, and newer wizards only put in the ...
    (microsoft.public.vc.mfc)
  • Re: Trigraphs forever
    ... Wouldn't it be better to go the other way, add a pragma to enable ... with old compilers). ... the standard, so they are unaware of the pitfalls of gets or that it is ...
    (comp.std.c)