define vs typedef

Started by
21 comments, last by AcePilot 18 years, 10 months ago
TheRealMAN11 >> Well, the reason I prefer macros over inline functions and templates and such, is that it is simply a, in a way, text replacement. Therefore, you have some more basic freedoms with macros. Unless I'm mistaken, inline functions can't exactly declare new functions or variables, can they?
I think I will leave the rest up to these words: Preference-Depedent.


EDIT: Along with the messiness as <b>JohnBolton</b> states comes ways to fix these little errors. Just keep in mind that this will work properly:<br><pre>#define getmax(a,b) ((a)&gt;(b)?(a):(b))</pre>However, there isn't really a point to using this macro because there aren't any real special circumstances that inline or template functions can't handle.<br>NOTE: I'm not sure about the entire point of my post though… heh.
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
Advertisement
*retracts his post*

didnt think such an arguement would occur over such a little question :p

guess thats what happens when people start debating the ever dreaded "define"
I am assuming you are using the define keyword for variables. For me, it is
really a matter of preference, for example

#define MATRIX_def float[4][4]typedef float MATRIX_tdef[4][4];// MATRIX_def uses #define, while MATRIX_tdef is a typedef.MATRIX_tdef mul(MATRIX_tdef a, MATRIX_tdef b){    MATRIX_tdef ret;    ret = a * b;// Dont try this code out, the multiplication operator wont work    return ret;}MATRIX_def mul(MATRIX_def a, MATRIX_def b){    MATRIX_def ret;    ret = a * b;// Dont try this code out, the multiplication operator wont work    return ret;}


Both functions should work, after preprocessor-compilation, this is what the code should look like:


// preprocessor "#define" has been removedtypedef float MATRIX_tdef[4][4];MATRIX_tdef mul(MATRIX_tdef a, MATRIX_tdef b){    MATRIX_tdef ret;    ret = a * b;    return ret;}float[4][4] mul(float[4][4] a, float[4][4] b){    float[4][4] ret;    ret = a * b;    return ret;}     // MATRIX_def has been replaced by float[4][4]



So really, in my opinion, it doesnt really make a difference.

This topic is closed to new replies.

Advertisement