Thread: variable declerations

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    17

    Question variable declerations

    hi there,

    do this codes differs? if so which way? what about performance?

    Code:
    type a,b,c,d,e, ........................ , x2, x3, x4...... , y9;
    Code:
    type a;
    type b;
    type c;
    .
    .
    .
    .
    type y9;

  2. #2
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    no, the 2nd is just longer

  3. #3
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    It is a matter of style, no more. I would use an array with enums as indexes, but that is my style.

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    If "type" is a pointer then there is a difference. You must add the * to each variable you want declared as a pointer under the first scenario.

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Right.... There will be no difference in the compiled code.

    The 2nd method will allow more space for more-descriptive variable names, or comments (explanations of what the variable are for).

    Use whatever method makes the code easier to read & understand.

    If you need that many similar variables, it looks like an array (or a few arrays) might be the way to go.... It depends on the program... how the variables are related, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 12:07 PM
  2. static class variable vs. global variable
    By nadamson6 in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2005, 03:31 PM
  3. Replies: 2
    Last Post: 04-12-2004, 01:37 AM
  4. write Variable and open Variable and get Information
    By cyberbjorn in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2004, 01:30 AM
  5. Variable question I can't find answer to
    By joelmon in forum C++ Programming
    Replies: 3
    Last Post: 02-12-2002, 04:11 AM