473,788 Members | 3,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

initializer is not a constant error ??

Ok, i'm a real c n00b but i needed a piece of code for some work i was
doing. Initially i was running the stuff under linux and using gcc to
compile the c code and it worked fine but now i need to port it to
windows and when i try to compile the same code with the visual studio
command line tool "cl" i get this error:

const.c(92) : error C2099: initializer is not a constant
const.c(97) : error C2099: initializer is not a constant

with the relevant lines of the const.c code being:

ln 92 double INFINITY = 1.0/0.0; /* 99e999; */
ln 97 double NAN = 1.0/0.0 - 1.0/0.0;

Now i have no real idea what this is doing so i was wondering why i
compiles fine uner gcc but not under windows, oh the command i am
using is:

cl /c const.c

Is there a compile option i need to set or will i have to change the
code?

Any help would be great, thanx.

Dave.
Nov 14 '05 #1
2 7221
is*****@hotmail .com (David Green) writes:
const.c(92) : error C2099: initializer is not a constant
const.c(97) : error C2099: initializer is not a constant

with the relevant lines of the const.c code being:

ln 92 double INFINITY = 1.0/0.0; /* 99e999; */
ln 97 double NAN = 1.0/0.0 - 1.0/0.0;


Both of these invoke undefined behavior due to division by zero.
Maybe that's why the compiler regards them as not being constant
expressions. I can't think of another reason right now.

If your implementation has a C99-compliant <math.h>, you can just
#include <math.h> to get ready-made macros for these.
--
"I don't have C&V for that handy, but I've got Dan Pop."
--E. Gibbons
Nov 14 '05 #2
Ben Pfaff wrote:
is*****@hotmail .com (David Green) writes:

const.c(92) : error C2099: initializer is not a constant
const.c(97) : error C2099: initializer is not a constant

with the relevant lines of the const.c code being:

ln 92 double INFINITY = 1.0/0.0; /* 99e999; */
ln 97 double NAN = 1.0/0.0 - 1.0/0.0;

Both of these invoke undefined behavior due to division by zero.
Maybe that's why the compiler regards them as not being constant
expressions. I can't think of another reason right now.

If your implementation has a C99-compliant <math.h>, you can just
#include <math.h> to get ready-made macros for these.


He did mention that he's using Visual C, which does not (to the best of
my knowledge) support C99 (though it apparently supports it in some
ways, and it's certainly possible that this is one of them).

To the best of my knowledge, outside of C99 there is not a portable way
to generate INF and NAN. But there's probably a system-specific way. I'd
recommend checking the documentation for a function or a predefined
constant.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
19571
by: Todd Nathan | last post by:
Hi. have this code and compiler problem. GCC 2.95.3, BeOS, error "initializer element is not constant" #ifdef FILEIO { static struct { char *sfn; FILE *sfd; } stdfiles = {
2
1964
by: Mantorok Redgormor | last post by:
struct mystruct { int a; int b; }; struct mystruct x = { 10, 10 }, y = x; What section in the standard says that y needs a constant? And why can't it resolve x so that y can have a copy of its values?
3
2458
by: Levi Campbell | last post by:
Hi, I'm trying to debug an app someone else wrote called eMixer. Here's the log contents: cc -O3 -funroll-loops -c -o main.o main.c cc -O3 -funroll-loops -c -o nctgui.o nctgui.c cc -O3 -funroll-loops -c -o mixer.o mixer.c mixer.c: In function `open_soundcard_alsa':
3
1394
by: vib | last post by:
Hi there, I wish to get some advice on the problem I face in initializing a table. Here is the code. I've an array of strings, ptrNameString . I want to initialize a table, mySoftKeyTable with some contents of the string from the array. This initialization is not in any function, but rather outside of any function. However, the compiler complaints, the related lines( L1, L2, L3, L4) of "Initializer element is not constant". I
2
2018
by: aarklon | last post by:
Hi all, Recently i was reading a c book which contained a section called C pitfalls. it had a paragraph on the following lines:- ------------------------------------------------------------------- using nonconstant expressions in an initializer list -------------------------------------------------------------------
7
10210
by: Paul Edwards | last post by:
On ecgs (gcc) 2.91.57 and on gcc 3.2.3 I am getting the error "initializer element is not constant" on the below code. The code compiles fine with other compilers I have. Is this valid C89 code? extern int *b; int *a = b; int main(void)
1
1811
varuns
by: varuns | last post by:
hi i m stuck while compiling my code for generating bindings for c code to be accessible from python i have read the ext.pdf available at python.org, and i think i have done every thing right. But while compilation an error message is displayed demobox.c:495: error: initializer element is not constant demobox.c:495: error: (near initialization for `_PyDemoBox_methods.ml_meth') ......
1
4120
varuns
by: varuns | last post by:
hi i m stuck while compiling my code for generating bindings for c code to be accessible from python i have read the ext.pdf available at python.org, and i think i have done every thing right. But while compilation an error message is displayed demobox.c:495: error: initializer element is not constant demobox.c:495: error: (near initialization for `_PyDemoBox_methods.ml_meth')
16
2808
by: Gowtham | last post by:
Hi, I had some C code written which initialized a global variable as: FILE *yyerfp = stdout; This used to work fine in older versions of gcc. Now, when I tried to compile this code (with gcc 3.2.3), I got errors like:
0
9655
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.