Different outputs in different environments.

  • Thread starter Raja Kiran Kumar Reddy Sandireddy
  • Start date
R

Raja Kiran Kumar Reddy Sandireddy

Hi,

I observed a very strange phenomenon with my program outputs. I run
my C-program on MSDOS environment and the same program on Sun-session.
I get same output when the input is a small file (which has details
for a circuit with, say, less than 30 logic gates). But, the same
program processes the inputs differently in these environment and give
different results when the input file describes a larger circuit (say,
more than 100 gates). I use lot of memory to hold the data in the
file and then process it.
The program's output is the expected (correct) one in the MSDOS
environment, while the output with the UNIX environment is not the
expected one.

Can anyone clarify this to me.

Thanks,
Raja Sandireddy.
 
J

Jens.Toerring

Raja Kiran Kumar Reddy Sandireddy said:
I observed a very strange phenomenon with my program outputs. I run
my C-program on MSDOS environment and the same program on Sun-session.
I get same output when the input is a small file (which has details
for a circuit with, say, less than 30 logic gates). But, the same
program processes the inputs differently in these environment and give
different results when the input file describes a larger circuit (say,
more than 100 gates). I use lot of memory to hold the data in the
file and then process it.
The program's output is the expected (correct) one in the MSDOS
environment, while the output with the UNIX environment is not the
expected one.

Without more information to go by I can only guess, but the most
likely cause would seem to be that the program relies on some kind
of either implementation or undefined behaviour. A very simple
example would be having variables defined like this

double a;
int c[ 4 ];
char int;

and now writing past the end of array 'b' (i.e. try to use b[4]). On
some implementation/architecture it could modify the content of 'a',
on some other the content of 'c' and on another one none of them.
And there are lots and lots of similar possibilities, so without
carefully checking your program it's impossible to tell why it would
behave differently on different machines. And, of course, if you do
lots of floating point calculations you could end up with quite some
different results if the program wasn't written to deal with possible
rounding errors in a reasonable way.

Regards, Jens
 
C

CBFalconer

Raja said:
I observed a very strange phenomenon with my program outputs. I run
my C-program on MSDOS environment and the same program on Sun-session.
I get same output when the input is a small file (which has details
for a circuit with, say, less than 30 logic gates). But, the same
program processes the inputs differently in these environment and give
different results when the input file describes a larger circuit (say,
more than 100 gates). I use lot of memory to hold the data in the
file and then process it.
The program's output is the expected (correct) one in the MSDOS
environment, while the output with the UNIX environment is not the
expected one.

Can anyone clarify this to me.

You have invoked undefined behavior. Check line 456.
 
F

Flash Gordon

On 31 Aug 2004 23:03:34 -0700
(e-mail address removed) (Raja Kiran Kumar Reddy Sandireddy) wrote:

Can anyone clarify this to me.

Go down to your nearest wine making kit supplier and buy some clarifier.
Alternatively, post the minimum COMPILABLE program that exhibits the
problem and we may be able to help. However, all anyone can say at the
moment is that you have a problem.
 
R

Raja Kiran Kumar Reddy Sandireddy

Hi all,

Thanks for reading and responding to the message. I got the problem
cleared. I did not initialize an allocated memory block (i used
malloc). The MSDOS environment was initialization these bytes to 0s
which would make my program run correctly while the Sun-session
compiler was initializing this to some arbitrary value. When I used
calloc, everything is working fine.

I thought of sending the program in my earlier mail so that you guys
can have a better idea of what i was talking, but it was a 500 line
program and to accompany it, it has some input files.

Anyways, thanks for responding.

-Raja Sandireddy.
 
O

Old Wolf

A very simple example would be having variables defined like this

double a;
int c[ 4 ];
char int;

and now writing past the end of array 'b' (i.e. try to use b[4]).

Not enough coffee this morning? :)
 
J

Jens.Toerring

Old Wolf said:
(e-mail address removed)-berlin.de wrote:
A very simple example would be having variables defined like this

double a;
int c[ 4 ];
char int;

and now writing past the end of array 'b' (i.e. try to use b[4]).
Not enough coffee this morning? :)

Obviously;-) And too much editing something that (as far as I remember)
was actually at least more correct before (I started with three variables
called 'a', 'b', and 'c' and then things got a bit mixed up...)

Regards, Jens
 
P

Peter Shaggy Haywood

Groovy hepcat Raja Kiran Kumar Reddy Sandireddy was jivin' on 1 Sep
2004 10:52:01 -0700 in comp.lang.c.
Re: Different outputs in different environments.'s a cool scene! Dig
it!
I thought of sending the program in my earlier mail so that you guys
can have a better idea of what i was talking, but it was a 500 line
program and to accompany it, it has some input files.

A man called his doctor on the phone and said, "Doc, it hurts when I
do this. Can you tell me what's wrong with me?" He then hung up. Can
you imagine what was going through the doctor's mind at that moment?
Later the man called the doctor again and said, "Doc, I would have
sent you an X-ray of my whole body, but I would have had to use a very
large envelope." What do you think the doctor thought of his patient
at that point? Do you think he was very impressed?
If you don't post code for us to analyse, how can we possibly know
what's wrong with it? If the code is too big, cut it down to the
smallest *complete* program (meaning enough to compile and run) that
shows the problem. Cut out everything that is irrelevant to solving
your problem. If it's still rather big, post it anyhow. Or, at least,
post a link to it on the 'Net. You have to give us something to go on,
otherwise there's nothing we can do for you. We're not mind readers.
Please remember that the next time you ask for help.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
 
P

pete

Peter said:
Groovy hepcat Raja Kiran Kumar Reddy Sandireddy was jivin' on 1 Sep
2004 10:52:01 -0700 in comp.lang.c.
Re: Different outputs in different environments.'s a cool scene! Dig
it!


A man called his doctor on the phone and said, "Doc, it hurts when I
do this. Can you tell me what's wrong with me?" He then hung up. Can
you imagine what was going through the doctor's mind at that moment?

Henny Youngman.
 
A

Arthur J. O'Dwyer

Henny Youngman.

What was Henny Youngman doing, going through the doctor's mind?

-Arthur,
obviously he hung up so quickly because talking on the phone hurt him
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top