Thread: & sign

  1. #1
    Enthusiastic Beginner balazsbotond's Avatar
    Join Date
    Mar 2007
    Location
    Érd, Hungary
    Posts
    20

    & sign

    Code:
       struct Node;
       typedef Node *Node_ptr;
    
       struct Node {
          char word[MAX_WORD_LENGTH];
          Node_ptr ptr_to_next_node;
       };
    
       void delete_node(Node_ptr &a_list, char a_word[]);
    What does & mean here? Is it the same as "Node_ptr& a_list" (a reference to a pointer)?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Yes, the whitespace here is insignificant.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by balazsbotond View Post
    What does & mean here? Is it the same as "Node_ptr& a_list" (a reference to a pointer)?
    Yes. Whitespace never matters in C++.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I wouldn't say "never". But it doesn't in this case.

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Daved View Post
    I wouldn't say "never". But it doesn't in this case.
    Yeah, I've had problems in the past with nested template declarations, having to put space between '<' and '>' characters. I thought it was a broken compiler.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Yeah, I've had problems in the past with nested template declarations, having to put space between '<' and '>' characters. I thought it was a broken compiler.
    I believe that is due to a 'bug' in the C++ Standard, due to be fixed in the next revision of the Standard.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by laserlight View Post
    I believe that is due to a 'bug' in the C++ Standard, due to be fixed in the next revision of the Standard.
    I always thought the use of "<>" for template stuff was stupid. It should have been "[]". The problem is that '<<' and '>>' are tokens so there has to be some hairy interaction between the parser and the lexer to get it right. If they had only chosen "[]" instead there would have been no such problems.

  8. #8
    Enthusiastic Beginner balazsbotond's Avatar
    Join Date
    Mar 2007
    Location
    Érd, Hungary
    Posts
    20
    Thanks!

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    You'd be exchanging one problem for another. Look at this:
    Code:
    foo[5]
    Under your syntax, is that the type "array of five foos" or is it "template foo instantiated with 5 as the value of its non-type template parameter"?
    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

  10. #10
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by CornedBee View Post
    You'd be exchanging one problem for another. Look at this:
    Code:
    foo[5]
    Under your syntax, is that the type "array of five foos" or is it "template foo instantiated with 5 as the value of its non-type template parameter"?
    Good point.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. mantissa, sign, exponent
    By -EquinoX- in forum C Programming
    Replies: 28
    Last Post: 03-05-2008, 02:25 PM
  2. Sign ' is the same as \' ?
    By George2 in forum C Programming
    Replies: 1
    Last Post: 11-23-2007, 07:32 AM
  3. My own itoa()
    By maxorator in forum C++ Programming
    Replies: 18
    Last Post: 10-15-2006, 11:49 AM
  4. Handle on MSN Messenger's Sign In "button"?
    By jmd15 in forum Windows Programming
    Replies: 3
    Last Post: 07-16-2005, 09:28 PM
  5. Sign Up!: The Third Round, both contests
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 54
    Last Post: 07-20-2002, 05:46 PM