Thread: Variable Declarations

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

    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,

    int a;
    int b;
    int c;
    equivalent to

    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
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 04:11 AM