:Want to have ur opinions on having function calls like the one stated
:below:
:function funcA ( struct A *st_A , struct B *st_B )
:{ st_A->a = st_B->a >}
:Basically Is it a nice programming practice to have functions like this
Yes.
:especially when we can access both the structures in the calling
rogram ???
I'm not srue what you mean there?
:I want to know what will b the pros and cons of such calls ??
:Will such calls effect the speed of execution by loading and unloading
:the stack ????
With code this simple, your compiler may be able to inline the
operation, replacing the call with direct execution of the effects.
If a call is used, the overhead depends upon the ABI and upon the
architecture. When small numbers of values are passed in, it would be
common (but not certain) to pass the values in registers; the calling
program would see that the registers themselves are not being modified
and so would not need to save the registers upon the stack. The
return address may have to go on the stack, but that's dependant
upon the architecture and ABI: some ABIs are set up to save the
return address in a register, and it is up to the called routine to
save that register if the called routine decides the code is complex
enough to warrant it. On some architectures, the generated code might
be as little as move (A1),(A0); branch A7
Matters such as these, which require a fair knowledge of the architecture
and of the ABI, are beyond the C specifications, so they are not
usually discussed in comp.lang.c .
lz keep in mind that I m woking on a archaic system
and I m not the
ne who wrote the code ...
Suppose you were able to save two instructions per invocation by
doing the assignment directly, but doing so would require rewriting
the code. How long would it take to rewrite the code? How much
clarity would be lost in the code? Now, how much compute time would
be saved over the complete life of the program by not having to
execute those two instructions?
Say the rewrite took a working day (8 hours) and [considering you said
the system was archaic] suppose the machine runs at 500 MHz per clock
cycle, 2 cycles per instruction, so 4 cycles saved per invocation by
your optimization.
8 hours * 60 minutes/hour * 60 seconds/minute * 500,000,000 cyles/s /
(4 cycles/invocation) = 3,600,000,000,000 invocations
Thus you would need 3.6 trillion invocations just to break even.
Is that likely? Is shaving off an 8th of a microsecond per call
worth the effort?
When you are dealing with optimizations, worry about the parts of
your code that are -proven- to cause a bottleneck. For the rest
of your code, write it in the manner that will be most -maintainable-,
because the human maintenance for the rest of the code is likely to
consume far more time than would be used by the processor.