& sign

This is a discussion on & sign within the C++ Programming forums, part of the General Programming Boards category; 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[]); ...

  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
    20,968
    Yes, the whitespace here is insignificant.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,159
    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,317
    I wouldn't say "never". But it doesn't in this case.

  5. #5
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,159
    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
    20,968
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,159
    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,892
    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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,159
    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, 01:25 PM
  2. Sign ' is the same as \' ?
    By George2 in forum C Programming
    Replies: 1
    Last Post: 11-23-2007, 06: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

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