Variable Declarations

This is a discussion on Variable Declarations within the C++ Programming forums, part of the General Programming Boards category; Please answer only if you're sure about it.. It may be a kind of noobish , but I can't help ...

  1. #1
    Registered User
    Join Date
    Jun 2008
    Location
    New Delhi, India
    Posts
    3

    Variable Declarations

    Please answer only if you're sure about it.. It may be a kind of noobish , but I can't help it

    When the object code is prepared during compilation,
    is

    Code:
    int a;
    //... 
    int b;
    //...
    int c;
    equivalent to

    Code:
    int a,b,c;
    Where in the first case, declarations aren't in consecutive lines?
    I mean, does it make the program's executable smaller/faster in anyway to declare them by the second method?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,739
    If you are curious, generate the intermediate assembly code of the two versions of the program in question and compare. With what you have given, the result should be exactly the same.

    Anyway, the rule of thumb here is to declare variables near first use.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. static class variable vs. global variable
    By nadamson6 in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2005, 03:31 PM
  2. Replies: 10
    Last Post: 09-27-2005, 12:49 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, 03:11 AM

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