Different code behaviour in Unix & Windows

T

tech guru

Robert said:
The point is that most of us aren't mind readers

I was expecting a solution from the other half! ;) (basically those who
would have encountered and solved similar problems).
and if you don't
provide any useful information about your problem we can't provide a
very useful answer.

I guess main motive behind my post was to find out the POSSIBLE reasons
which could cause the problem (given that the same piece of code runs
fine on Windows).
Your best bet is to reduce the problem to the
smallest *compilable* program that demonstrates the issue

One way to debug, off course, is to reduce it to a smaller program
while another approach could be to put printf() statements. I was just
trying/hoping to avoid this lenghty debugging part.
and post it
along with your question. Make sure you indicate what is wrong and how
it differs from your expectations.

Robert Gamble

Generally, it is not too difficult to fix an issue once the exact
problem is understood.
 
K

Keith Thompson

tech guru said:
Also, the (wrong) big numbers are consistently 2147324616 or 2147321288
which is just less than 2^31 (=2147483648).

If I compile like 'gcc3 -o objName sourceName.c', it complains about
round() & sqrt() even if math.h is included. At the same time, even if
I do not have math.h and compile using Makefile (with gcc3 only) it
does not complain!

Any idea?

<http://www.c-faq.com/fp/libm.html>

If you don't have a "#include <math.h>", you don't have declarations
for round() and sqrt(), and the compiler assumes that they're
functions returning int (at least in C90). I'd expect a warning
unless you mask it with a cast. With or without a cast, you're
invoking undefined behavior. Don't do that.
 
R

Robert Gamble

tech said:
I was expecting a solution from the other half! ;) (basically those who
would have encountered and solved similar problems).


I guess main motive behind my post was to find out the POSSIBLE reasons
which could cause the problem (given that the same piece of code runs
fine on Windows).

There are numerous reasons why you might be encountering the problem
you describe. Why would you waste our time and your time asking us to
try to enumerate every possible situation that might fit your vague
description when you could spend a few minutes to reduce your code,
post it here, and get a clear answer.
One way to debug, off course, is to reduce it to a smaller program
while another approach could be to put printf() statements. I was just
trying/hoping to avoid this lenghty debugging part.

Debugging comes with the job, if you can't be bothered to at least take
the steps neccessary to help us help you then you are wasting your time
here.

Robert Gamble
 
S

stefan.ciobaca

Please post compiler versions for both Windows and Linux. And system
architecture e.g. x86/amd etc.

gcc --version will pop the version number for gcc. Not sure what you
are using under Windows.

As a general piece of advice, compile your code with

gcc -Wall -o bla bla.c

and fix every warning properly. That might give you a hint as to what
is broken.

If it still doesn't work, tell us about what problem you're solving,
how is it that it is numeric and you're using longs instead of doubles.
Posting some example code could also help identify the problem.
 
T

tech guru

Robert said:
There are numerous reasons why you might be encountering the problem
you describe. Why would you waste our time and your time asking us to
try to enumerate every possible situation that might fit your vague
description when you could spend a few minutes to reduce your code,
post it here, and get a clear answer.

There isn't any compulsion that everyone who reads a post must reply.
One should rather never reply if s/he doesn't have a clue about the
problem and/or s/he is not able to provide any answer based on the info
provided in the post. If one is willing to help, s/he can always ask
for more info as par her/his theory about the possible reasons (like
(e-mail address removed) and many others have done).
Debugging comes with the job, if you can't be bothered to at least take
the steps neccessary to help us help you then you are wasting your time
here.

Robert Gamble

Debugging is always one option I have got. What I am trying here is to
get some QUICK help, so that I would have to spend less time in
debugging.
 
I

Ian Collins

tech said:
Debugging is always one option I have got. What I am trying here is to
get some QUICK help, so that I would have to spend less time in
debugging.
Then post an example that exhibits your problem.

The alternative is a bandwidth wasting thread like this one.
 
K

Keith Thompson

Ian Collins said:
Then post an example that exhibits your problem.

The alternative is a bandwidth wasting thread like this one.

There's always a slight possibility that a vague description will ring
a bell in someone's head, if there happens to be someone out there
who's had a very similar problem.

But it's not the way to bet, and I think we've seen that that's not
likely to happen in this case.
 
E

Eric

tech said:
Hi Vladimir,


In some places, I am doing like a += b. But I think the result would
still be fit into a. Moreover, I am getting wrong result even where I
am just finding minimum & maximum values by comparison.

What is the logic behind it? :) Btw, line 42 is a blank line in my
program, followed by #define. If I ignore comments/blank lines, line 42
points to the definition of a member in a structure.

Thanks,
Saumi

Are you just thick? No one knows what the **** line 42 is cuz YOU DIDNT POST
YOUR CODE! So how is anyone going to be able to figure out whats wrong?
Example of your posting technique:
Q: "My program crashes. What is wrong with it?"
Answer: "Line 42"
Get it?
Eric
 
K

Keith Thompson

Eric said:
Are you just thick? No one knows what the f*** line 42 is cuz YOU DIDNT POST
YOUR CODE! So how is anyone going to be able to figure out whats wrong?
Example of your posting technique:
Q: "My program crashes. What is wrong with it?"
Answer: "Line 42"
Get it?
Eric

Eric, please chill out. Several people have already explained the 42
joke, but when "tech guru" wrote the above it's likely he hadn't seen
any of the explanations yet. Someone not familiar with Hitchhiker's
Guide To The Galaxy might not realize that the "line 42" comment is
intended to be a joke.

Your point is valid, but it's already been made here several times,
and YOU DON'T NEED TO SHOUT.
 
E

Eric

Keith said:
Eric, please chill out. Several people have already explained the 42
joke, but when "tech guru" wrote the above it's likely he hadn't seen
any of the explanations yet. Someone not familiar with Hitchhiker's
Guide To The Galaxy might not realize that the "line 42" comment is
intended to be a joke.

Your point is valid, but it's already been made here several times,
and YOU DON'T NEED TO SHOUT.
as you wish...
 
V

Vladimir S. Oka

tech guru opined:
There isn't any compulsion that everyone who reads a post must reply.
One should rather never reply if s/he doesn't have a clue about the
problem and/or s/he is not able to provide any answer based on the
info provided in the post. If one is willing to help, s/he can always
ask for more info as par her/his theory about the possible reasons
(like (e-mail address removed) and many others have done).

As many of us did, but you're stubbornly refusing to provide any really
useful information. Instead you engage in an endless game of "Why
don't you? Yes, but..."

Show us some code that gives you the problem you describe.
Debugging is always one option I have got. What I am trying here is
to get some QUICK help, so that I would have to spend less time in
debugging.

You're /already/ debugging, and not very efficiently by the looks of it
(complete with dragging along a bunch of strangers who volunteered to
help).
 
R

Robert Latest

On 18 Apr 2006 14:59:22 -0700,
in Msg. said:
gcc -Wall -o bla bla.c

Make that: gcc -W -Wall -ansi -pedantic -O -o bla bla.c

"-W -Wall" catches more than just "-W".
"-ansi -pedantic" makes the thread topical in this group.
"-O" catches uninitialized variables.

robert
 
R

Robert Latest

On 18 Apr 2006 15:36:21 -0700,
in Msg. said:
There isn't any compulsion that everyone who reads a post must reply.
One should rather never reply if s/he doesn't have a clue about the
problem and/or s/he is not able to provide any answer based on the info
provided in the post.

Thanks, Mr "tech guru", for teaching us how to behave on Usenet.
Debugging is always one option I have got. What I am trying here is to
get some QUICK help, so that I would have to spend less time in
debugging.

What you get when starting a discussion on Usenet is just that, a
discussion. During which you have the chance to learn much more about
your problem than you probably would have imagined before. If you are
too impatient for that, Usenet is not the place for you.

robert
 
R

Robert Latest

On Tue, 18 Apr 2006 23:38:15 GMT,
in Msg. said:
There's always a slight possibility that a vague description will ring
a bell in someone's head, if there happens to be someone out there
who's had a very similar problem.

I had it when I ported a lot of DOS (Turbo C) stuff to Linux several
years ago. Buggy code doesn't port well.

robert
 
N

Nick Keighley

tech said:
Also, the (wrong) big numbers are consistently 2147324616 or 2147321288
which is just less than 2^31 (=2147483648).

what were they supposed to be?
If I compile like 'gcc3 -o objName sourceName.c', it complains about
round() & sqrt() even if math.h is included.

try linking with the math library (see the clc FAQ for more info)

gcc -lm etc.
At the same time, even if
I do not have math.h and compile using Makefile (with gcc3 only) it
does not complain!

as other posters have suggested bump up your warning levels to detect
non-portable code

gcc -ansi -pedantic -O2 etc.


There is no obvious per se reason why a well written mathematical
program
runs on windows but not on Unix. Earlier you talked about long,
implying it
was an integer program; now you are using round() and sqrt(), so is
this FP
maths?

Alos just how standard in round()? I'm pretty sure its not C89.
 
C

CBFalconer

tech said:
.... snip ...

Debugging is always one option I have got. What I am trying here
is to get some QUICK help, so that I would have to spend less
time in debugging.

And what you are actually doing is persuading more and more
participants to ignore you now and in the future, by refusing to
post a suitable cut-down program. If you won't help, why should
we?
 
V

Vladimir S. Oka

Nick Keighley opined:
try linking with the math library (see the clc FAQ for more info)

gcc -lm etc.

Alos just how standard in round()? I'm pretty sure its not C89.

It's not in my C89 draft, but it is in N1124, so I suppose it's C99.
 
K

Keith Thompson

Vladimir S. Oka said:
Nick Keighley opined:

It's not in my C89 draft, but it is in N1124, so I suppose it's C99.

round() is standard in C99, but not in C90.

I think we recently had a thread here where someone's compiler (I
think it was gcc) recognized round(), possibly implementing it with
inline code, but the system's <math.h> header didn't declare it. (The
compiler, headers, and library are all part of the implementation as
far as the standard is concerned, but if they're provided by different
vendors or other entities they can be inconsistent.) Since no
declaration for round() was visible, the compiler had to assume that
it returns int. (And no, casting the result to double is *not* a fix
for the problem; it merely masks the error.)

I have no idea whether that's the problem here, but it's worth
investigating.

But perhaps the OP has gotten the point by now that he needs to do
some debugging.
 
M

Mark McIntyre

There isn't any compulsion that everyone who reads a post must reply.

"tech guru", a word of advice. Don't start arguing with the regulars
about what you need to give us in order to get help. It will only
annoy the very people you need to contact.

In order for us to help, you need to give us more info, You've been
asked for that. You won't give it. We can't help. Its your move next.
Debugging is always one option I have got. What I am trying here is to
get some QUICK help, so that I would have to spend less time in
debugging.

Nobody is going to help you to be lazy.

Mark McIntyre
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top