Thread: Stupid Question

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    4

    Stupid Question

    I know this is a stupid question but it there any difference between:

    type* identifer;

    and

    type * identifer;

    and

    type *identifer;

    or is it just whitespace?

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Just whitespace.

    [edit]But someone will come along and also note this:
    http://c-faq.com/decl/charstarws.html, which also links to
    http://www.research.att.com/~bs/bs_faq2.html#whitespace
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I like keeping the pointer next to the type just because it's a pointer to a type.

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    4
    Thanks, I've been looking through some code (quite large examples) and it was scattered about both ways.

    I guessed it was because different people coded different parts but I was just checking thank you.

  5. #5
    ... arjunajay's Avatar
    Join Date
    May 2005
    Posts
    203
    putting * near the type confuses readers.
    eg:[code]
    int* ptr, normalvaraible; //here only ptr is a pointer if I'm correct...
    int *ptr, normalvaraible; // here it is clearer ???

  6. #6
    Registered User
    Join Date
    May 2006
    Location
    United States
    Posts
    10
    I tend to put spaces on both sides of the "*".
    But it really is all about personal preference.

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    25
    Quote Originally Posted by arjunajay
    putting * near the type confuses readers.
    eg:[code]
    int* ptr, normalvaraible; //here only ptr is a pointer if I'm correct...
    int *ptr, normalvaraible; // here it is clearer ???
    Yes, I agree with you. Supporting for the first style seems not very persuadable (just my opinion).

  8. #8
    Registered User Jaqui's Avatar
    Join Date
    Feb 2005
    Posts
    416
    Quote Originally Posted by Ari.Patrick
    I tend to put spaces on both sides of the "*".
    But it really is all about personal preference.
    true, when you are coding for yourself, personal preference is all that matters.

    false, when you are part of a development team, then you have to follow the coding standard adopted by that team, and if they choose int *ptr then you have to code it int *ptr, not as int* ptr or int * ptr.


    and Dave,
    there isn't actually any such thing as a stupid question. there are questions that are asked in a stupid way, but your question doesn't fall into that grouping either.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Question Probably
    By Kyrin in forum C Programming
    Replies: 2
    Last Post: 05-07-2006, 12:51 AM
  2. Replies: 7
    Last Post: 11-04-2005, 12:17 AM
  3. Stupid Question
    By digdug4life in forum C++ Programming
    Replies: 22
    Last Post: 05-17-2005, 11:43 AM
  4. stupid, stupid question
    By xelitex in forum C++ Programming
    Replies: 5
    Last Post: 12-22-2004, 08:22 PM
  5. Stupid question: What does Debugger do?
    By napkin111 in forum C++ Programming
    Replies: 6
    Last Post: 05-02-2002, 10:00 PM