Good C programming style

S

Skarmander

Chris said:
Sensei wrote:




How big is "big"?

#define NEEDS(mill, n) \
do { \
if (vm->myHeap->available < (Size) (n)) \
(FREEZE(), millRegenerate( mill ), MELT()); \
} while (0)
#define INLINE inline

INLINE void needs(? mill, Size n) {
if (vm -> myHeap -> available < n) {
freeze();
millRegenerate(mill);
melt();
}
}

S.
 
C

Chris Dollin

Skarmander said:
#define INLINE inline

INLINE void needs(? mill, Size n) {
if (vm -> myHeap -> available < n) {
freeze();
millRegenerate(mill);
melt();
}
}

Won't work.

FREEZE() is a macro, MELT is a macro, both of them use variables
available where NEEDS is called - such as, for example, `vm`.

And `inline` wasn't routinely available when this code was written;
furthermore, failure to inline is likely to make the code run
significantly more slowly. Since this is part of the system core,
it would matter.
 
S

Skarmander

Chris said:
Skarmander wrote:




Won't work.

FREEZE() is a macro, MELT is a macro, both of them use variables
available where NEEDS is called - such as, for example, `vm`.

Pass as parameters or promote to global status. Probably the latter.
"Global" with respect to the smallest unit appropriate, of course.
And `inline` wasn't routinely available when this code was written;
furthermore, failure to inline is likely to make the code run
significantly more slowly. Since this is part of the system core,
it would matter.

Sure. If inlining really won't work and profiling shows you you do need
that performance, take the macro route.

S.
 
C

Chris Dollin

Skarmander said:
Pass as parameters or promote to global status. Probably the latter.
"Global" with respect to the smallest unit appropriate, of course.


Sure. If inlining really won't work and profiling shows you you do need
that performance, take the macro route.

Inlining really didn't work.
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top