Re: Histogram of character frequencies
- From: Barry Schwarz <schwarzb@xxxxxxxxx>
- Date: Wed, 05 Dec 2007 18:14:47 -0800
On Sun, 2 Dec 2007 06:39:20 -0800 (PST),
rajash@xxxxxxxxxxxxxxxxxxxxxxxx wrote:
James Kuyper wrote:
rajash@xxxxxxxxxxxxxxxxxxxxxxxx wrote:
Johannes Bauer wrote:
rajash@xxxxxxxxxxxxxxxxxxxxxxxx schrieb:
int x[256]; // frequenciesGlobal.
It's completely acceptable to have variables defined at file scope in
C!
What's acceptable is not always a good idea. Global objects have many
disadvantages; they should be avoided except when necessary; they aren't
necessary in this case.
In this case they help simplify the code - the array gets initialized
to 0 at compile-time, instead of needing extra code for an
initialization loop bad for efficiency!
But you could achieve the same effect without any of the problems that
global variables cause simply by declaring the array static inside the
function.
snip
OK you're right I should remember that. However I don't think it's the
end of the world - the standard library is always linked in so the
right functions will be found in the end by the linker.
The headers have very little to do with what the linker will link in
with your code and everything to do with the compiler generating
correct code. Leaving out stdlib.h and calling malloc introduces
undefined behavior. Leaving out string.h and passing anything other
than a void* or char* to memcpy or memset introduces undefined
behavior.
snip
Remove del for email
.
- Follow-Ups:
- Re: Histogram of character frequencies
- From: Flash Gordon
- Re: Histogram of character frequencies
- References:
- Histogram of character frequencies
- From: rajash
- Re: Histogram of character frequencies
- From: Johannes Bauer
- Re: Histogram of character frequencies
- From: rajash
- Re: Histogram of character frequencies
- From: James Kuyper
- Re: Histogram of character frequencies
- From: rajash
- Histogram of character frequencies
- Prev by Date: Very beautiful girls and many useful resources and more,please check it out
- Next by Date: Re: LDBL_MAX -1.#QNAN0e+000 with MinGW?
- Previous by thread: Re: Histogram of character frequencies
- Next by thread: Re: Histogram of character frequencies
- Index(es):
Relevant Pages
|