Friday, November 14, 2014

function and function-like macro

if we use the same name for those things. avoid the prepocessor will expand the function first, we usaully add parenthese to prevent.

simple example

#include <stdio.h>
#define test(x) __test(x)
#define __test(x) printf("\n%d\n", x + 1);

int test(int x);
#undef test

int main()
{
    test(1);
}
int (test)(int x)
{
    printf("\n%d\n", x);
}

Referemce

http://stackoverflow.com/questions/13600790/what-do-the-parentheses-around-a-function-name-mean

No comments:

Post a Comment

Register Transfer Level Design with Verilog (1) [ebook]

設計程式之所以有趣不外乎是它的千變萬化,同樣的結果卻有不同的寫法。 但這些不同寫法當中也並沒有分誰對誰錯,也沒有制定標準來規範何事該用何解。 這也就是我們設計者的珍貴!! [1] Primitive Instantiations 在Verilog中最基本的邏輯...