[Coco] Drivewire mixed results...

David Gacke dgacke at ektarion.com
Mon Sep 29 11:47:49 EDT 2008


Hi Chuck,

This isn't quite accurate.


     > That's
     > why I get annoyed when I see people write
     > 
     > char func();
     > or
     > short func();
     > 
     > Because it demonstrates a lack of the fundamental rules of C,
     > specifically, the default promotions.  The same thing applies to
     > function arguments, you can't pass anything smaller than an int to
     > a
     > function.  Hell, you can't perform any operation that involves a
     > binary
     > operator on anything smaller than an int, for that matter.
     > 
     > C.
     > 
     > 


While in this particular case it really doesn't apply, Alex is correct.

Especially with SSE(SIMD) enabled processors, you should pass and return
what you need. 

This lets the compiler make the most of its optimization possibilities. If
the compiler wants to promote the variable, so be it.

If you force a variable promotion by returning something larger than what
you need, the compiler won't be able to take advantage of knowing the true
variable size, and might not be able to make an optimization where one was
available.

Also, you are assuming in the above statement that the compiler didn't
inline the function on you. Bad assumption on certain compilers with certain
optimizations set.



Dave Gacke





More information about the Coco mailing list