Forum Topic - float.h:
   
float.h  
With 4.3.3 the following line doesn't compile:

#include <float.h>

static double minTime = DBL_MAX;

error: initializer element is not constant.

Is that a new C rules ?  In float.h if STDC_VERSION is <= 199901 DBL_MAX would be equal to 0xf.ffffffffffff8p+1020, but 
instead it's _CSTD _Dbl._Dmax._Double
Re: float.h  
Mario Charest wrote:
> With 4.3.3 the following line doesn't compile:
> 
> #include <float.h>
> 
> static double minTime = DBL_MAX;
> 
> error: initializer element is not constant.
> 
> Is that a new C rules ?  

C has never permitted initializing global variables with non-constants.

Regards,

Ryan Mansfield
RE: float.h  

> -----Original Message-----
> From: Ryan Mansfield [mailto:community-noreply@qnx.com]
> Sent: May-12-09 9:51 AM
> To: general-toolchain
> Subject: Re: float.h
> 
> Mario Charest wrote:
> > With 4.3.3 the following line doesn't compile:
> >
> > #include <float.h>
> >
> > static double minTime = DBL_MAX;
> >
> > error: initializer element is not constant.
> >
> > Is that a new C rules ?
> 
> C has never permitted initializing global variables with non-constants.
> 

This code compiles fine with gcc 3.3.5.  One would expect DBL_MAX to be a constant, no?

> Regards,
> 
> Ryan Mansfield
> 
> 
> _______________________________________________
> General
> http://community.qnx.com/sf/go/post29257
> 
Re: float.h  
Mario Charest wrote:
> 
>> -----Original Message-----
>> From: Ryan Mansfield [mailto:community-noreply@qnx.com]
>> Sent: May-12-09 9:51 AM
>> To: general-toolchain
>> Subject: Re: float.h
>>
>> Mario Charest wrote:
>>> With 4.3.3 the following line doesn't compile:
>>>
>>> #include <float.h>
>>>
>>> static double minTime = DBL_MAX;
>>>
>>> error: initializer element is not constant.
>>>
>>> Is that a new C rules ?
>> C has never permitted initializing global variables with non-constants.
>>
> 
> This code compiles fine with gcc 3.3.5.  One would expect DBL_MAX to be a constant, no?

The compiler version doesn't matter. It compiled with gcc 3.3.5 because 
of the OS headers you were using. If you used 4.3.3 with 6.3.2 headers, 
it would work fine, and similarly if you used 3.3.5 with 6.4.x headers, 
you would get the same error.

In 6.3.x, the OS headers explicitly set __STDC_VERSION__ to 199901L and 
DBL_MAX was a const expression in float.h.

Regards,

Ryan Mansfield
RE: float.h  

> -----Original Message-----
> From: Ryan Mansfield [mailto:community-noreply@qnx.com]
> Sent: May-12-09 10:46 AM
> To: general-toolchain
> Subject: Re: float.h
> 
> Mario Charest wrote:
> >
> >> -----Original Message-----
> >> From: Ryan Mansfield [mailto:community-noreply@qnx.com]
> >> Sent: May-12-09 9:51 AM
> >> To: general-toolchain
> >> Subject: Re: float.h
> >>
> >> Mario Charest wrote:
> >>> With 4.3.3 the following line doesn't compile:
> >>>
> >>> #include <float.h>
> >>>
> >>> static double minTime = DBL_MAX;
> >>>
> >>> error: initializer element is not constant.
> >>>
> >>> Is that a new C rules ?
> >> C has never permitted initializing global variables with non-
> constants.
> >>

I understand that Ryan.

> >
> > This code compiles fine with gcc 3.3.5.  One would expect DBL_MAX to
> be a constant, no?
> 
> The compiler version doesn't matter. It compiled with gcc 3.3.5 because
> of the OS headers you were using. If you used 4.3.3 with 6.3.2 headers,
> it would work fine, and similarly if you used 3.3.5 with 6.4.x headers,
> you would get the same error.
> 
> In 6.3.x, the OS headers explicitly set __STDC_VERSION__ to 199901L and
> DBL_MAX was a const expression in float.h.

That's the part that confuses me.  I mean the standard must have change for DBL_MAX to be a non constant which breaks 
existing code, at any rate I understand that's the ways it is and will have to fix the code. Thanks.


> 
> Regards,
> 
> Ryan Mansfield
> 
> 
> _______________________________________________
> General
> http://community.qnx.com/sf/go/post29268
> 
Re: float.h  
Mario Charest wrote:
> That's the part that confuses me.  I mean the standard must have change for DBL_MAX to be a non constant which breaks 
existing code, at any rate I understand that's the ways it is and will have to fix the code. Thanks.

Yes, I believe in C99 DBL_MAX to changed to be a const expression to 
specifically so it used as an global var initializer. By default, gcc 
follows gnu89. If you specify, -std=c99 to the compiler, it will define 
__STDC_VERSION__ to be 199901L and DBL_MAX will be defined as a const expr.

Regards,

Ryan Mansfield