lost value??

This is a discussion on lost value?? within the C++ Programming forums, part of the General Programming Boards category; consider this code Code: int add(int x, int y); int main() { add(5, 7); return 0; } what happens to ...

  1. #1
    "Why use dynamic memory?"
    Join Date
    Aug 2006
    Posts
    186

    lost value??

    consider this code
    Code:
    int add(int x, int y);
    
    int main()
    {
    	add(5, 7);
    
    	return 0;
    }
    what happens to the value of add function in main() ??
    is it lost because we did not assign it to another variabl??
    "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg."-Bjarne Stroustrup
    Nearing the end of finishing my 2D card game! I have to work on its 'manifesto' though <_<

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Pretty much, except obviously that won't compile unless you link to code that contains a definition of add() as declared.

  3. #3
    "Why use dynamic memory?"
    Join Date
    Aug 2006
    Posts
    186
    i just omitted the definition to illustrate the problem really quick
    just assume it's there =)
    "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg."-Bjarne Stroustrup
    Nearing the end of finishing my 2D card game! I have to work on its 'manifesto' though <_<

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    If I was a smart compiler, I would optimize the whole program into nothing, since that's basically what it does.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    You'd have to be smart enough to prove that add() has no side effects, but aside from that, yeah. In fact, if add() is marked pure, most compilers will do just that.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lost devices in Direct3D
    By VirtualAce in forum Game Programming
    Replies: 10
    Last Post: 12-09-2006, 06:41 AM
  2. I lost my laptop, DVD and money
    By Sang-drax in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 10-01-2004, 07:13 PM
  3. lost disk
    By Benzakhar in forum Linux Programming
    Replies: 7
    Last Post: 01-11-2004, 05:18 PM
  4. Lost ID number
    By ripper079 in forum C++ Programming
    Replies: 13
    Last Post: 10-04-2002, 12:51 PM
  5. API, LOST... help
    By Unregistered in forum Windows Programming
    Replies: 5
    Last Post: 03-13-2002, 02:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21