473,581 Members | 2,204 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Length of Variable Names Affect Compiled Executable?

Does the length of my C variable names have any affect, performance-wise, on
my final executable program? I mean, once compiled, etc., is there any
difference between these two:
number = 3;
n = 3;

I know its setting aside storage for the variable itself; does it also use
up more storage if the variable name is longer? I realize it would probably
take quite a lot of long variable names to make any impact if so, but I was
just curious if anyone knew...
Sep 26 '06 #1
16 6706
John wrote:
Does the length of my C variable names have any affect, performance-wise, on
my final executable program? I mean, once compiled, etc., is there any
difference between these two:
number = 3;
n = 3;
The Standard doesn't say.

Normally compiled code will be the same. It is conceivable for a C
intepreter to take longer.
--
Thad
Sep 26 '06 #2
In article <45************ ***********@aut h.newsreader.oc tanews.com>,
Thad Smith <Th*******@acm. orgwrote:
>John wrote:
>Does the length of my C variable names have any affect, performance-wise, on
my final executable program? I mean, once compiled, etc., is there any
difference between these two:
number = 3;
n = 3;
>The Standard doesn't say.
>Normally compiled code will be the same. It is conceivable for a C
intepreter to take longer.
-potentially- there might be debug information in the executable
that records the original variable names; a larger variable name might
result in a larger debug section; depending on the OS details,
that -might- result in a slightly larger initiation time (e.g. because
a larger file is being parsed apart to link and load.) But likely
any such effect would be trivial compared to the other factors affecting
executable file size, such as the amount of code, or the optimization
level.
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
Sep 27 '06 #3

John wrote:
Does the length of my C variable names have any affect, performance-wise, on
my final executable program? I mean, once compiled, etc., is there any
difference between these two:
number = 3;
n = 3;

I know its setting aside storage for the variable itself; does it also use
up more storage if the variable name is longer? I realize it would probably
take quite a lot of long variable names to make any impact if so, but I was
just curious if anyone knew...
If we compare variable names in C with in assemble language,we can see
as follows:
In C:
int number = 3;
int n;
n=number;

In asm: (ebp point to the top of stack before going into the
procedure.)
mov dword ptr [ebp-4],3
mov eax,dword ptr [ebp-4]
mov dword ptr [ebp-8],eax

The C compiler hold a table to storage the variable names,but after
compiled to assemble language,the table will be distroyed.

In a same question:
We can write in assemble language like this:
In asm:
..data
number dw 3
n dw ?
....
..code
....
mov ax,number
mov n,ax
....
the same question is :is there any difference between these two
variable names?
After it complied to opcode,it may be executed like this:
....
A10000 ( mov ax,[0000])
A30200 ( mov [0002],ax)
....

So,the table holded by assemble compiler will be destroyed after it
compiled to opcode.

Sep 27 '06 #4
John wrote:
I know its setting aside storage for the variable itself; does it also use
up more storage if the variable name is longer?
No. On some compilers, if you compile with a "debugging symbols" switch
enabled, a symbol table of some sort will be generated which will make
the code larger, but it would be a rather broken implementation that led
to a performance cost as a result.

Sep 27 '06 #5
>Does the length of my C variable names have any affect, performance-wise, on
>my final executable program? I mean, once compiled, etc., is there any
difference between these two:
number = 3;
n = 3;
By posting your article, you've probably used up much more CPU time than
your program will ever use during its lifetime. So stop worrying about
its performance.

The C standard does not require a program to have any kind of
performance: good, bad, sucky, awful, better than, or worse than.
>I know its setting aside storage for the variable itself; does it also use
up more storage if the variable name is longer? I realize it would probably
take quite a lot of long variable names to make any impact if so, but I was
just curious if anyone knew...
A program compiled with debugging symbols will probably take up
more *DISK* storage depending on symbol length. These symbols may
or may not ever get into memory when the program is run.

It is possible, especially if you have a habit of using terabyte-long
symbol names, that name length could affect the runtime of the
dynamic linker that might be used on program startup.

Sep 27 '06 #6
Walter Roberson wrote:
In article <45************ ***********@aut h.newsreader.oc tanews.com>,
Thad Smith <Th*******@acm. orgwrote:
>John wrote:
>>Does the length of my C variable names have any affect, performance-wise, on
my final executable program? I mean, once compiled, etc., is there any
difference between these two:
number = 3;
n = 3;
>The Standard doesn't say.
>Normally compiled code will be the same. It is conceivable for a C
intepreter to take longer.

-potentially- there might be debug information in the executable
that records the original variable names; a larger variable name might
result in a larger debug section; depending on the OS details,
that -might- result in a slightly larger initiation time (e.g. because
a larger file is being parsed apart to link and load.) But likely
any such effect would be trivial compared to the other factors affecting
executable file size, such as the amount of code, or the optimization
level.
Typically though, that debug information is not loaded by other
than special tools - such as a debugger.

Then again, this implementation specific.
Sep 27 '06 #7
Ark
John wrote:
Does the length of my C variable names have any affect, performance-wise, on
my final executable program? I mean, once compiled, etc., is there any
difference between these two:
number = 3;
n = 3;

I know its setting aside storage for the variable itself; does it also use
up more storage if the variable name is longer? I realize it would probably
take quite a lot of long variable names to make any impact if so, but I was
just curious if anyone knew...

An often overlooked case is when by using the stringize operator you
introduce names (or similar) to the code. E.g.
#define FYI(x) printf("FYI: %s = %d\n", #x, x)
............... .
FYI(n);
FYI(number_of_c haracters_grows );

A typical case of something similar is the assert macro (which people
sometimes leave active in the release code by #undef'ing NDEBUG by hand).

In these cases the length of a name matters - but all things considered,
not terribly much.

--
Ark
Sep 27 '06 #8
John said:
Does the length of my C variable names have any affect, performance-wise,
on
my final executable program? I mean, once compiled, etc., is there any
difference between these two:
number = 3;
n = 3;

I know its setting aside storage for the variable itself; does it also use
up more storage if the variable name is longer? I realize it would
probably take quite a lot of long variable names to make any impact if so,
but I was just curious if anyone knew...
I have read the parallel replies with great interest and amusement. It's
amazing how much juice you can squeeze from C.

Nevertheless, *in general* the answer to your question is "no". Yes, various
people have drawn attention to various exceptions to that answer, which you
may wish to take into account. But in the general case, your implementation
will (or can be told to) discard all such information.

Thus, using b instead of CurrentBalance is an unnecessary "optimisati on"
which will, in the general case, have no impact on performance. Write
clear, readable code using good algorithms and descriptive identifiers.
Worry about performance only in the extremely rare cases where good
algorithms don't deliver sufficient performance to meet your users' needs.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 27 '06 #9
In article <45********@new s.broadpark.no> ,
=?ISO-8859-1?Q?=22Nils_O=2 E_Sel=E5sdal=22 ?= <NO*@Utel.nowro te:
>Walter Roberson wrote:
>-potentially- there might be debug information in the executable
that records the original variable names; a larger variable name might
result in a larger debug section; depending on the OS details,
that -might- result in a slightly larger initiation time (e.g. because
a larger file is being parsed apart to link and load.)
>Typically though, that debug information is not loaded by other
than special tools - such as a debugger.
>Then again, this implementation specific.
Sure, typically not loaded, but unless the implementation' s standards
for the format of executables is such that the debug information must
be the -last- thing in the executable, then the code that loads
the executable into working memory must read the debug information
to get past it to the other important information.

The loader might fseek() around the debug information and thus not
actually read it in, but fseek() can interfere with automatic OS
pre-read of files so fseek() is not -always- faster than just reading
the characters and throwing them away. Interestingly, using lots
of large variable names can, by increasing the debug section size,
drive the debug section size closer to the point where fseek() is
worthwhile ;-)
--
"law -- it's a commodity"
-- Andrew Ryan (The Globe and Mail, 2005/11/26)
Sep 27 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
3940
by: opt_inf_env | last post by:
Hello, It is strange to me that html and css use different names for variables which define the same properties. For example if I whant to define text color from html document I write: <body text="#dddddd"> And to define text color from css file I need to write:
18
1735
by: Carramba | last post by:
Hi! I am wondering what is the best way to control that compiler manage variable names longer then 8 signs. Does it enought to set 2 variables with the same name and difference after 8 sign and se thats happends? -- Thanx in advance! ;-)
15
1951
by: Thomas Scheiderich | last post by:
I thought I read that the case for the variable names is important. For example Dim Wheel As Integer Wheel here is a different variable from WHEEL. Is this correct?
2
1896
by: Hamish Symington | last post by:
Hello, I'm trying to re-code a site which I wrote in PHP into ASP.NET using Visual Basic .NET. Something PHP has which has proved invaluable is the concept of variable variables. I haven't had any success with working out how to do it and hoped someone might be able to help.
6
6138
by: Marcus Kwok | last post by:
I am designing a GUI (my question is not about GUIs) and I have named my variables using a regular naming scheme. However, in order to simplify the code using these variables, I have created an array of non-owning pointers to these variables. I am trying to write a macro to generate these variable names for me, but I am not sure if what I...
10
7102
by: John Salerno | last post by:
If I want to have a list like this: where the first part of each tuple is a variable name and the second part is a label for the user to see, such as a form like this: First Name: ________ Last Name: ________
5
2627
by: panthera | last post by:
Hi, I have a problem regarding generating variable names in my program.Suppose I have 10 variables b0,b1,b2...b9.They are NOT in an array.And I want to randomly select one of them and get its value.So I pick a random number between 0 and 9 and concat it with 'b' to get the name of this variable.But how do I get the value of this variable? ...
4
3326
by: Victor Lagerkvist | last post by:
Hello, I have the need to parse variable names from a string and save them somewhere safe for future usage. Here's my first attempt (I don't have any rules for valid names yet) - but I have a feeling that it's unnecessary complex? Any input would be greatly appreciated. #include <stdio.h> #include <stdlib.h> int get_ops(char *sen, char...
5
2337
by: jennic | last post by:
Hi, I have an online shop that uses Sunshop php shopping cart and I have attempted to get help through their forum but no-one responds with assistance. I need to install a tracking code on my site and I was given the tracking code and told I need to insert the variable names for the order total and sales id. But I have no idea what these are where...
0
7792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8149
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8304
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8175
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6553
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5674
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5364
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3805
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.