• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Arguments are not being passed correctly -- Please help
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Arguments are not being passed correctly -- Please help


  • Subject: Re: Arguments are not being passed correctly -- Please help
  • From: Markian Hlynka <email@hidden>
  • Date: Wed, 5 Oct 2005 12:18:54 -0600

not 100% sure here, but I think...
std::cout << sum3(100.0, 100.0, 100.0) << std::endl; //breakpoint

sum3 returns a double. but where does that double go? well, it must be put on the stack somewhere, implicity. I don't know what the order of creation here is, but I'm guessing that either cout is called after sum3, or that after sum3 returns, some IOprocessing takes place in cout, calls some private functions in the IOstream library, and stomps on the return value. Or maybe it copies it too soon, since you're returning a double, and not a double&. Does that make sense? There's probably a subtle difference between the two compiles, like - g or -O or something, that's changing this.


So, I suggest trying to change sum3's return value to a double&.

If I have the wrong solution, or the right solution for the wrong reasons, someone please let me know!

Markian

On Oct 3, 2005, at 23:58, Berndt Jung wrote:

Below is a very simple example.  The output should, as you may guess
be 300, but the first argument when the function is called always
changes to zero, and the output is 200.  The strange thing is that if
compiled and run on the command line, there isn't an issue.  Within
xcode 2.0 I get the above behavior.  Interestingly, if execution
pauses, via a breakpoint at the comment below, everything works. There
are three files, main.cpp, gzmath.h, and gzmath.cpp:

main.cpp

#include "gzmath.h"
#include <iostream>

int main (int argc, char * const argv[]) {
    std::cout << sum3(100.0, 100.0, 100.0) << std::endl;  //breakpoint
    return 0;
}

gzmath.h

double sum3(double, double, double);

gzmath.cpp

#include "gzmath.h"

double sum3(double x, double y, double z) {
return x + y + z;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40cs.ualberta.ca


This email sent to email@hidden


----
Early to bed and early to rise, makes a man stupid and blind in the eyes.
--Mazer Rackham



_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Arguments are not being passed correctly -- Please help
      • From: Cameron Hayne <email@hidden>
    • Re: Arguments are not being passed correctly -- Please help
      • From: Markus Hitter <email@hidden>
References: 
 >Arguments are not being passed correctly -- Please help (From: Berndt Jung <email@hidden>)

  • Prev by Date: Re: Commenting/Uncommenting blocks of code at once
  • Next by Date: Re: Commenting/Uncommenting blocks of code at once
  • Previous by thread: Re: Arguments are not being passed correctly -- Please help
  • Next by thread: Re: Arguments are not being passed correctly -- Please help
  • Index(es):
    • Date
    • Thread