Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Different code behaviour in Unix & Windows

Reply
Thread Tools

Different code behaviour in Unix & Windows

 
 
tech guru
Guest
Posts: n/a
 
      04-18-2006
Robert Gamble wrote:
> tech guru wrote:
> > Hi Vladimir,
> >
> > > Did you check that all intermediate results don't overflow? E.g.:
> > >
> > > a = (b * c) / d;
> > >
> > > will still blow up in your face if `(b * c)` overflows, even if your
> > > algorithm guarantees that the final result will fit into `a`.

> >
> > 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.
> >
> > > The problem is most likely on line 42.

> > 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.

>


> 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.

 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      04-18-2006
"tech guru" <(E-Mail Removed)> writes:
> Also, the (wrong) big numbers are consistently 2147324616 or 2147321288
> which is just less than 2^31 (=214748364.
>
> 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.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
 
 
 
Robert Gamble
Guest
Posts: n/a
 
      04-18-2006
tech guru wrote:
> Robert Gamble wrote:
> > tech guru wrote:
> > > Hi Vladimir,
> > >
> > > > Did you check that all intermediate results don't overflow? E.g.:
> > > >
> > > > a = (b * c) / d;
> > > >
> > > > will still blow up in your face if `(b * c)` overflows, even if your
> > > > algorithm guarantees that the final result will fit into `a`.
> > >
> > > 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.
> > >
> > > > The problem is most likely on line 42.
> > > 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.

> >

>
> > 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).


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.

> > 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.


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

 
Reply With Quote
 
stefan.ciobaca@gmail.com
Guest
Posts: n/a
 
      04-18-2006
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.

Robert Gamble wrote:
> tech guru wrote:
> > Robert Gamble wrote:
> > > tech guru wrote:
> > > > Hi Vladimir,
> > > >
> > > > > Did you check that all intermediate results don't overflow? E.g.:
> > > > >
> > > > > a = (b * c) / d;
> > > > >
> > > > > will still blow up in your face if `(b * c)` overflows, even if your
> > > > > algorithm guarantees that the final result will fit into `a`.
> > > >
> > > > 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.
> > > >
> > > > > The problem is most likely on line 42.
> > > > 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.
> > >

> >
> > > 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).

>
> 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.
>
> > > 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.

>
> 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


 
Reply With Quote
 
tech guru
Guest
Posts: n/a
 
      04-18-2006

Robert Gamble wrote:
> tech guru wrote:
> > Robert Gamble wrote:
> > > tech guru wrote:
> > > > Hi Vladimir,
> > > >
> > > > > Did you check that all intermediate results don't overflow? E.g.:
> > > > >
> > > > > a = (b * c) / d;
> > > > >
> > > > > will still blow up in your face if `(b * c)` overflows, even if your
> > > > > algorithm guarantees that the final result will fit into `a`.
> > > >
> > > > 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.
> > > >
> > > > > The problem is most likely on line 42.
> > > > 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.
> > >

> >
> > > 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).

>


> 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 Removed) and many others have done).

>
> > > 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.

>
> 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.

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      04-18-2006
tech guru wrote:
>
> 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.

--
Ian Collins.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      04-18-2006
Ian Collins <(E-Mail Removed)> writes:
> tech guru wrote:
>> 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.


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.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      04-18-2006
"tech guru" <(E-Mail Removed)> wrote in news:(E-Mail Removed) ups.com:

[ Please do not snip attributions ]

> Hi Vladimir,

....
>> The problem is most likely on line 42.

....
> What is the logic behind it?


http://en.wikipedia.org/wiki/The_Ans...and_Everything



--
A. Sinan Unur <(E-Mail Removed)>
(remove .invalid and reverse each component for email address)
 
Reply With Quote
 
Eric
Guest
Posts: n/a
 
      04-19-2006
tech guru wrote:

> Hi Vladimir,
>
>> Did you check that all intermediate results don't overflow? E.g.:
>>
>> a = (b * c) / d;
>>
>> will still blow up in your face if `(b * c)` overflows, even if your
>> algorithm guarantees that the final result will fit into `a`.

>
> 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.
>
>> The problem is most likely on line 42.

> 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

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      04-19-2006
Eric <(E-Mail Removed)> writes:
> tech guru wrote:
>> Hi Vladimir,
>>
>>> Did you check that all intermediate results don't overflow? E.g.:
>>>
>>> a = (b * c) / d;
>>>
>>> will still blow up in your face if `(b * c)` overflows, even if your
>>> algorithm guarantees that the final result will fit into `a`.

>>
>> 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.
>>
>>> The problem is most likely on line 42.

>> 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 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.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Different behaviour in different struct declaration types __PaTeR C Programming 7 01-01-2009 12:13 AM
socket-module: different behaviour on windows / unix when a timeoutis set Mirko Vogt Python 0 07-09-2008 06:02 PM
debugger behaviour different to execution behaviour Andy Chambers Java 1 05-14-2007 09:51 AM
compile C programs with UNIX system calls (= Unix Programs??) jrefactors@hotmail.com C Programming 18 01-10-2005 03:35 AM
compile C programs with UNIX system calls (= Unix Programs??) jrefactors@hotmail.com C++ 12 01-10-2005 03:35 AM



Advertisments