LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   problem of "NaN" in redhat 7.3, with gcc-2.96 while running c_code (https://www.linuxquestions.org/questions/programming-9/problem-of-nan-in-redhat-7-3-with-gcc-2-96-while-running-c_code-133553/)

mkh 01-10-2004 09:51 PM

problem of "NaN" in redhat 7.3, with gcc-2.96 while running c_code
 
I need some help from this forum. Initially it is posted in the "newbie-linux" forum, where it is suggested to move it to this forum.

I am compiling a program in c language in my linux machine-redhat linux 7.3, gcc version 2.96. The program involves some arrays of "double precision floating points", defined and evaluated under different routines.
While running the program I get some elemnts of the arrays to be "nan". (These elements are computed in one operation, stored in the array and used later for further computation.) The problem is peculiar in the sense that when I try to use the stored value of the element and try to learn its value just before using, it shows "nan". But when I check, if really it was an illegal computation by using "printf" immediately sfter coputation/storing the element, it shows a value to the element and stores the same value, allows its use in later operations; and the problem of "nan" vanishes. i.e., using "printf" after computation of the element removes the problem of having a "nan". However that is not desirable.
When I searched in the net I came across some reference to similar instances but could not get a clear indication to the "follow up action" (probably due to my own limitation, as I am quite new to linux os). I hope some suggestion from this forum will help me coming out of my problem.


(The original code was written by a third party. I am trying to modify it to suit my requirement and there, I get the problem. I am enclosing the "problematic part" of the program.

Removed on 12/1/04 at 1.05 p.m.)

To be honest I am not having any clue about the problem.
Thanking in advance,

:Pengy:

itsme86 01-11-2004 04:00 AM

That's just way too much code for me to wrap my brain around without a full working program ;) Maybe you could post a link to a tarball of it so I can play around.

In my experience, having a printf() or some other function call fix an odd problem usually means that you're reading from a corrupted piece of memory. Maybe you're not reserving enough space and without the printf() call that memory is being used somewhere else or something?

slackie1000 01-11-2004 01:38 PM

hi there,
mkh, can you compile this part of the program?
i took a look but i was not able even to compile... a lot error concerning undeclared variable...
we need the header of the program... declarations...
like itsme86 said it is complicated to help with such a code... we can not figure out where is the mistake without compiling too much code..
Regards

mkh 01-12-2004 01:17 AM

Thanks Slakie1000 and itsme86 for your response. Perhaps I could not present my problem well enough. Also, before putting in to the post I did not compile the part_progarm separately, but picked the problematic part. Sorry for the inconvenience caused.
However, in the mean-time a google_session helped me where observation was that "removing any mismatch in declaration of the routine in the main" may help. Following the suggestion I was benefited (initially the routines were not defined explicitly in the main) and at present it is working.
Thanks again to all concerned.
:Pengy:


All times are GMT -5. The time now is 05:50 PM.