Clarification....

This is a discussion on Clarification.... within the C Programming forums, part of the General Programming Boards category; At various times I've seen and used both of the following... Code: int* test; int *test; I've also seen it ...

  1. #1
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547

    Clarification....

    At various times I've seen and used both of the following...

    Code:
    int* test;
    
    int *test;
    I've also seen it used both ways in tutorials I've studied. Both appear to get the same result (a pointer to an int, in the example).

    Is there any meaningful difference?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,650
    Read Stroustrup's take on the FAQ Is ``int* p;'' right or is ``int *p;'' right?
    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
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by laserlight View Post
    Read Stroustrup's take on the FAQ Is ``int* p;'' right or is ``int *p;'' right?
    Yep, read that...

    Reason I'm asking is for some old code that has a bug I've never found.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    If just moving the * causes the bug, then you have a buggy compiler.

    Code:
    int *    p, q;
    int     *p, q;
    Which of these helps you to figure out the type of q?
    Yes, this is very poor style, but it doesn't stop it from happening.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Salem View Post
    If just moving the * causes the bug, then you have a buggy compiler.
    That's not what I said... I said I wanted clarification if it *might* be the problem. The answer was no, which is good enough for me.


    Code:
    int *    p, q;
    int     *p, q;
    Which of these helps you to figure out the type of q?
    Yes, this is very poor style, but it doesn't stop it from happening.[/QUOTE]

    I don't stack declarations like that. As part of my commenting scheme I identify the function of each variable as I declare it.

    If I did however... I would use the second form since it is visually more indicative of function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. clarification: behavior of type_info::before
    By Sebastiani in forum C++ Programming
    Replies: 11
    Last Post: 04-04-2008, 06:53 PM
  2. WM_DISPLAYCHANGE clarification
    By JasonD in forum Windows Programming
    Replies: 1
    Last Post: 11-10-2006, 01:27 AM
  3. Need a clarification here
    By bithub in forum A Brief History of Cprogramming.com
    Replies: 30
    Last Post: 12-27-2004, 12:06 AM
  4. exercise clarification truth table
    By curlious in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2003, 06:28 PM
  5. A little clarification?
    By Dr Nick in forum C++ Programming
    Replies: 2
    Last Post: 06-20-2002, 01:47 PM

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