V
vishnu
Hi friend,
i have a problem in my program what is the use of static function in C
lang?
plz help me
i have a problem in my program what is the use of static function in C
lang?
plz help me
vishnu said:i have a problem in my program what is the use of static function in C
lang?
vishnu said:Hi friend,
i have a problem in my program
what is the use of static function in C
lang?
They are hugely useful.vishnu said:Hi friend,
i have a problem in my program what is the use of static function in C
lang?
plz help me
Malcolm said:The other problem is that Fred, who is doing audio, might also need a idct8
function. In his case the 8 means that it is dealing with 8-bit samples.
So by just declaring the loadjpeg function with external linkage, and making
everything else static, I protect my code, don't pollute namespace, and make
it clear to Sheila that I am contracting to load a jpeg and return the bits,
but I don't provide any math routines or anything else.
That is probably a good snapshot of current compiler practise, butAnother benefit of static is to give additional freedom to compiler to
do optimizations. The compiler knows the function is local to this
translation unit and can do things like inlining. I remember reading
someone
commenting that it would have been far better for functions to default to
static
rather than global (external linkage). But I guess its too late to change
that now
and it is always better to write new functions as static if possible.
Malcolm said:That is probably a good snapshot of current compiler practise, but
technology changes.
There is no reason a compiler running on a modern PC cannot load the whole
of a largeish program into memory in C source form, and do a full compile,
within a few seconds.
> In the days when 66Mhz was leading edge, of course you
needed the object file / linker workaround to make compile times acceptable.
(It was the same story with "register". Nowadays it is unusual for the
programmer to be able to make better decisions than the compiler.)
The other point is that runtime efficiency isn't as important as it was.
Most computers nowadays are fast enough, and a good program is one that does
what it says and is easy to use, not one that responds quickly.
Having said that, I have just entered the brave world of Beowulf cluster
massively (well, 40 nodes) parallel supercomputing, and I am resorting to
Fortran to speed things up a bit.
That's the real answer. Usually the priority is to have clean,Flash Gordon said:The reason it is best to write functions as static if possible is not only
because of the compiler, it is also because of the human reader. If a
function is static them you know it is only used locally (unless its
address is taken) which limits how much you have to look at when trying to
fix a bug in it. Otherwise you have to check where else it might be called
from just in case something relies on the behaviour you are about to
change.
I got a new PC a few weeks ago, and it has 2 GB of memory installed.That depends on how large the source base is. Loading the source base of
openoffice in to memory and compiling it will take more than a few seconds
on a modern PC.
The reason is that the compiler is designed to treat core as a limitedIf you think that is no longer required now you don't work on large
projects. Try looking up the build time fir a Gentoo Linux system where
everything is built from source.
^^^^^Performance will probably always be an issue because people will always
want the software to do more. So you should always make it easy for the
Usually you are right - there's no point throwing cycles away. However youoptimiser and maintainer by them the information you have, such as that a
function is only called from within the one translation unit.
vishnu said:Hi friend,
i have a problem in my program what is the use of static function in C
lang?
plz help me
You must avoid using static functions
at all costs if there are dynamic
functions available! Use dynamic functions whenever possible.
The other point is that runtime efficiency isn't as important as it was.
Most computers nowadays are fast enough, and a good program is one that does
what it says and is easy to use, not one that responds quickly.
pete said:static functions are a feature of standard C.
"dynamic functions" means nothing in the context of standard C.
Did I say it meant anything?
pete said:static functions are a feature of standard C.
"dynamic functions" means nothing in the context of standard C.
Did I say it meant anything?
Absolutely un-true!
Clark said:Well, by using it, you certainly implied that it meant something.
Unless, that is, you're in the habit of using meaningless terms.
I'm in the habit of giving appropriate answers to stupid questions. It
is obvious to me that the OP knows near to nothing about functions in C
or about the effect of the keyword static. In other words, he knows
almost nothing. If he knew about those topics,
I have noticed that there is a far more vindictive streak in this NG
these days compared to when I started reading it 15 off years ago.
Whilst no one wants to do home work for some one you can always point
them in the right direction of study.
When people come here to ask "the experts" they don't expect them to
behave like self righteous pompous twats.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.