What does the suffix * mean?

This is a discussion on What does the suffix * mean? within the C++ Programming forums, part of the General Programming Boards category; Sorry for this being a really newbie question; I know that I read it in one of the tutorials but ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    15

    What does the suffix * mean?

    Sorry for this being a really newbie question; I know that I read it in one of the tutorials but I simply can't find it now...

    What I mean is a variable ending with a *, like
    Code:
    int my_var*;

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,807
    A compiler error.
    Ones like this though
    Code:
    int *myVar;
    Are called pointers
    Woop?

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    15
    Maybe it wasn't a variable.. but -something- ends with *...

  4. #4
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    maybe you saw it written as
    Code:
    int* myvar;
    which is pretty much what prog-bman just showed you... and it's evil. don't do it.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  5. #5
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    That's how I always declare pointers.
    Code:
    int *pointer;
    Looks weird. I guess you could do:
    Code:
    int * pointer;
    For a compromise...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    I can't think of any valid C++ code ends with a *. Maybe a function prototype with a pointer parameter and no variable name specified:
    Code:
    void foo(int* );
    >> and it's evil. don't do it.
    major_small must be kidding. Don't take that seriously.

  7. #7
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by Daved
    major_small must be kidding. Don't take that seriously.
    no, I'm not. consider this:
    Code:
    int* myVar1,myVar2;
    that makes it look like you may have intended both to be pointers, where only the first one is a pointer... and it just gets messy... for example:
    Code:
    int* myVar1,myVar2,myVar3,*myVar4,myVar5;
    usually I declare pointers like so:
    Code:
    int*myVar1;
    int myVar2;
    as you can see, I generally declare each variable on it's own line.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  8. #8
    Registered User Jaqui's Avatar
    Join Date
    Feb 2005
    Posts
    416
    ohhh, Major Small is using old school declarations, not overloading any one line.
    makes for much easier to read declarations.
    Quote Originally Posted by Jeff Henager
    If the average user can put a CD in and boot the system and follow the prompts, he can install and use Linux. If he can't do that simple task, he doesn't need to be around technology.

  9. #9
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    void junk (vector <Books*>& v);

    hmm.. thats like the only time i can see it on the rite side is in a funtion like it was said .
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  10. #10
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    >> no, I'm not. consider this

    I wouldn't consider that to be a question of evil. It's more a question of style. I'd put the evilness on the declaration of multiple variables on one line if something had to be called evil.

    Consider this:
    Code:
    int myVar1,myVar2,myVar3,myVar4,myVar5 = 0;
    Same issue, but = 0 is not evil, and there is nothing wrong with int myVar1 = 0;.

    My personal style is int* myVar. I never declare multiple pointers on the same line. I rarely declare multiple variables on the same line. This doesn't make the code extraordinarily long, since I rarely declare many variables together (declare variables as locally as possible). I also don't put them on the same line since I always try to initialize variables (especially pointers) when I declare them. The benefit is that it makes clear to me that the type is a pointer to int.

    So int* myvar is not evil and IMO you can use it if you like.

  11. #11
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    I'll agree that it's a question of style, but that style is just evil.

    take a look at this page and tell me that it's not evil. Sure, it's just a style, but it's an evil style
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  12. #12
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    You're right. Certain styles can be evil.

    (But this is not one of them.)

  13. #13
    Registered User
    Join Date
    May 2005
    Posts
    28
    Quote Originally Posted by Daved
    You're right. Certain styles can be evil.

    (But this is not one of them.)
    I agree with Daved. Pointers are not a style and they are not evil. They are part of the language, and an important one at that.

  14. #14
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by MitchellH
    I agree with Daved. Pointers are not a style and they are not evil. They are part of the language, and an important one at that.
    erm, we weren't talking about the pointers themselves, but how you choose to declare them.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  15. #15
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    Hey wait, I said that putting the * next to the type is not evil:
    Code:
    int* myvar;
    I didn't say that pointers themselves aren't evil.

    They are.

    (Of course, I am only kidding, although I tend to agree with that link in spirit.)
    Last edited by Daved; 10-18-2005 at 09:11 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Suffix tree help!
    By wuzzo87 in forum C Programming
    Replies: 6
    Last Post: 09-07-2006, 12:03 AM
  2. Suffix Trees
    By jodders in forum C++ Programming
    Replies: 2
    Last Post: 02-23-2005, 12:45 PM
  3. suffix help.
    By milkyway_sushi in forum C++ Programming
    Replies: 1
    Last Post: 11-27-2004, 04:41 PM
  4. Suffix Array
    By bondinc in forum C Programming
    Replies: 1
    Last Post: 10-02-2002, 05:43 PM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM

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