Difference between "char* buf "and "char *buf"

This is a discussion on Difference between "char* buf "and "char *buf" within the C Programming forums, part of the General Programming Boards category; Hi everyone, I am working with someone else's code that uses a struct defined as ... Code: typedef struct RawFrame{ ...

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    5

    Difference between "char* buf "and "char *buf"

    Hi everyone,

    I am working with someone else's code that uses a struct defined as ...

    Code:
    typedef struct RawFrame{
    unsigned char* buf;
    } RawFrame;
    If it were ...

    Code:
    typedef struct RawFrame{
    unsigned char *buf;
    } RawFrame;
    then I would simply read this as a pointer called buf that points to char objects.

    How does the dereference (*) symbol being on the "char" instead of the pointer name (buf) change the meaning?

    Many thanks.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    It doesn't change it. It's a style preference.
    If you understand what you're doing, you're not learning anything.

  3. #3
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    Something to keep in mind about one style vs. the other:

    Code:
    char* x, y, z;
    Some people consider the above style to be a bad idea as it is tempting to read the declaration as three char pointers, when in fact there is one char pointer and two regular chars, like so:

    Code:
    char *x, y, z;
    Of course if one was to declare three char pointers in the same line, it would look more like this:

    Code:
    char *p, *q, *r;
    ~/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Difference Equations / Recurrence Relations
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-05-2007, 10:26 AM
  2. What's the difference between var++ and ++var
    By ulillillia in forum C Programming
    Replies: 6
    Last Post: 05-31-2007, 02:27 AM
  3. telnet
    By MrJake in forum C++ Programming
    Replies: 18
    Last Post: 11-13-2002, 05:21 PM
  4. Email attachment via smtp - how?!
    By lucky760 in forum C++ Programming
    Replies: 2
    Last Post: 07-04-2002, 07:59 PM
  5. What is the Difference between ANSI C and non-ANSI C ?
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-24-2001, 05:55 AM

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