Re: can't initialize a constant using another constant?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Shriramana Sharma wrote:

> Quite some time since I wrote. I hope you are all keeping well. :)
> 
> A strange thing I ran across this evening. I was not allowed to do:
> 
> const double lunarSynodicMonth = 29.53059 ;
> const double daysLunarPhaseAngleTakesPerDegree = lunarSynodicMonth / 360.0 ;
> 
> I got the following error:
> 
> wdf-karanas.c:17: error: initializer element is not constant
> make: *** [wdf-karanas.o] Error 1
> 
> I would be grateful if anyone could shed some light. TIA.

In C, "const" is only relevant to pointer targets. Adding the "const"
modifier to a variable has no effect.

You need to change lunarSynodicMonth to a macro (#define) if you want
to be able to use it in an initialiser.

-- 
Glynn Clements <glynn@xxxxxxxxxxxxxxxxxx>
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux