Thread: indirection op attached to declaration

  1. #1
    Registered User
    Join Date
    Mar 2008

    indirection op attached to declaration

    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
    The edge of the known universe
    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
    Farncombe, Surrey, England
    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:
    char *a;
    char* a;
    char * a;
    char *    // newline counts as a whitespace.
    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:
    int* aptr, notaptr;
    notaptr is of type int, not int*.

    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