Symbols explanation plz

This is a discussion on Symbols explanation plz within the C++ Programming forums, part of the General Programming Boards category; little confused over the use of all the * symbols. I know that Code: int *var; creates a pointer to ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    34

    Symbols explanation plz

    little confused over the use of all the * symbols. I know that

    Code:
    int *var;
    creates a pointer to a variable but what about this use....

    Code:
    IDirect3DVertexBuffer9* vb;
    The star symbol is not next to the variable name so is it a pointer?
    And what about this one.....

    Code:
    BYTE** ppbData,
    any help would be greatly appreciated.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It means "pointer to", so "int *p" means that it p is a variable of pointer to integer.

    Two stars means "pointer to pointer to ...".

    A pointer is essentially a way to keep the location of another variable - like knowing the number of a safetydeposit box where something is stored.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,659
    Quote Originally Posted by te5la View Post
    little confused over the use of all the * symbols. I know that

    Code:
    int *var;
    creates a pointer to a variable...
    So it does, but I find it misleading.
    It should be
    int* var
    If you ask me.
    Why? Read on.

    but what about this use....

    Code:
    IDirect3DVertexBuffer9* vb;
    The star symbol is not next to the variable name so is it a pointer?
    This is indeed a pointer.
    My typical line of thinking is that a pointer is a type of variable.
    Therefore, as it is a type, the * appears next to the type.
    So...
    int*
    ...would mean it is a pointer, to an int.
    Get me here? A pointer is a type.
    Let's move on.

    And what about this one.....

    Code:
    BYTE** ppbData,
    any help would be greatly appreciated.
    If you follow the previous line of thinking, this means that this is a pointer to BYTE*. Yes, Everything left of the * is the type it points to.
    In other words, it's a pointer to a pointer to BYTE.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Jul 2008
    Posts
    34
    Thanks guys

  5. #5
    The larch
    Join Date
    May 2006
    Posts
    3,573
    That is, "*" is a separate token. C++ doesn't care about whitespace between tokens. Therefore all the following are correct and which placement you use is a style issue.

    Code:
    int* p;
    int *p;
    int * p;
    int
    *
    p;
    etc.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  6. #6
    Registered User
    Join Date
    Jun 2008
    Posts
    5
    yes, a pointer is a 'type' but also a 'variable'.

    int* p, i //looks as if they are both pointers at a glance
    int *p, i //makes more sense, easier to read

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,659
    There are always pitfalls.
    Because of this somewhat unclear rule, I do not define more than one pointer on the same line.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    It is clear: the * binds to the name, not the type.

    But yes, that seems reasonable.

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,659
    That is not clear.
    A name cannot consist of a *.
    It seems unlogical you can "bind" something to a variable. You assign, you use; that's all.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Some reading.

    One argument for the "emphasis on type" might be that T<int*> is a different beast than T<int>, so * appears to be rather part of the type.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux Putting my children to sleep with futex!?
    By Abs in forum Linux Programming
    Replies: 18
    Last Post: 02-12-2009, 05:43 PM
  2. Replies: 7
    Last Post: 02-02-2009, 06:27 AM
  3. Trouble with Windows/DirectX programming
    By bobbelPoP in forum Windows Programming
    Replies: 16
    Last Post: 07-08-2008, 02:27 AM
  4. Strange error?
    By MrLucky in forum C++ Programming
    Replies: 5
    Last Post: 02-04-2006, 02:01 PM
  5. symbols, no symbols, symbols ...
    By pavmarc in forum Linux Programming
    Replies: 0
    Last Post: 08-23-2005, 12:36 PM

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