Thread: indirection op attached to declaration

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    82

    indirection op attached to declaration

    Hi,
    I've been given some source code, and there's a structure called Datastruc, which a certain function has in its argument like so Somefunc( Datastruc* A).

    In other words, the * indirection op is not attached to the variable, but rather to the declaration, Datastruc. Is there really a difference? How can I call this function when I have already declared a variable Datastruc *A?

    Thanks in advance for help.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    There is no difference.
    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.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You can have any number of spaces [any whitespace, in fact] on either side of the *, zero or more, so these are all the same:
    Code:
    char *a;
    char* a;
    char*a;
    char * a;
    char *    // newline counts as a whitespace.
    a;
    Some people seem to prever to put the star next to the type, others prefer the star next to the variable name - it's a little bit misleading, in my opinion, to put it next to the type, since that can lead to someone else reading the code thinking that this declares two pointers:
    Code:
    int* aptr, notaptr;
    notaptr is of type int, not int*.

    --
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  2. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. NAQ: Everything you never wanted to know about CPP
    By evildave in forum C Programming
    Replies: 21
    Last Post: 12-12-2005, 10:56 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM