View Poll Results: Which do you use

Voters
35. You may not vote on this poll
  • char* name;

    10 28.57%
  • char *name;

    21 60.00%
  • char * name;

    4 11.43%
  • Other (plz post)

    0 0%

Which do you use?

This is a discussion on Which do you use? within the A Brief History of Cprogramming.com forums, part of the Community Boards category; OK, this is my first poll. I'd like to know how you declare pointers. I'll start. I use: char* name; ...

  1. #1
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448

    Which do you use?

    OK, this is my first poll. I'd like to know how you declare pointers. I'll start. I use:
    char* name;
    I put the * next to the type mainly to make clear that it's not the defference (sp?) operator.
    How about you?
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  2. #2
    Registered User quagsire's Avatar
    Join Date
    Jun 2002
    Posts
    60
    When you have
    Code:
    char* a,b;
    it looks as if both a and b is of type char*, but actually b is only of type char. To avoid confusion, rather use
    Code:
    char *a, b;
    to more clearly show what you mean

  3. #3
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    char *something;
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Always...

    type* pVariableName;

    ... and one declaration per line - no confusion.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    I used to use
    Type *variable;
    but i've heard it's better to use
    Type* variable;
    Plus, it makes more sense in many cases. I've been trying to change my habits towards the latter, but now and again I find myself typing Type *var.

  6. #6
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Well maybe I should change my habits as well.....any idea why this way char* var; might be better?
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  7. #7
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176
    i've heard that 'type *var' is better, because you're only making that variable a pointer, not everything in that decliration, so it makes more sense to keep the * with the single variable. makes sense to me.. it's what i've always used.
    If I had a world of my own, everything would be nonsense. Nothing would be what it is, because everything would be what it isn't. And contrariwise, what it is, it wouldn't be, and what it wouldn't be, it would. You see?

  8. #8
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    I use
    Code:
    std::string name;


    Seriously, I think char* name looks best and I never declare pointers and non-pointers on the same line anyway.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  9. #9
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    Purely asthetics, but I always place the asterisk between the type and variable:

    const char * str;

    void Foo(int * x);

    ...etc...



    ...and I never declare pointers and non-pointers on the same line anyway.
    That's the best practice.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  10. #10
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    I usually use char *pointer. But once in a while there comes a time that I need to use char* pointer.

    I never include non-pointers and pointers on same line either.

  11. #11
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    It really depends on you... since they are all correct, just choose what's more suitable to you...
    I prefere char *
    none...

  12. #12
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    char * duh;

    //i'll do multiple decl's of anything but pointers

    int a,b,c,d,e;

    bool go,stop,rewind;

    float * info;

    float * theNum;
    PHP and XML
    Let's talk about SAX

  13. #13
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    I usually use

    char* pointer

    because the * makes it a separate datatype. Putting it adjacent to char makes the type information close together and separate from the variable name.

    For multiple line declarations I usually do something like this:

    Code:
    char  Data,
        * Pointer;

  14. #14
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    char* always;

    for clarity if i have a char and a char* i put them on seperate lines

    char* p,* q;
    char c, ch;
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  15. #15
    Back after 2 years Panopticon's Avatar
    Join Date
    Dec 2002
    Posts
    262
    No difference between the two. But for the sake of declaring multiple pointers in one line, I use the *var method.
    I AM WINNER!!!1!111oneoneomne

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

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