宏定义

 如下:

file_one

#if !defined(CONFIG_NUMA) || !defined(CONFIG_HAVE_MEMORYLESS_NODES)

#ifndef set_numa_mem
#define set_numa_mem(node)
#endif
#ifndef set_cpu_numa_mem
#define set_cpu_numa_mem(cpu, node)                                                                                               
#endif

#endif  /* !CONFIG_NUMA || !CONFIG_HAVE_MEMORYLESS_NODES */

file_two

#ifndef set_cpu_numa_mem
static inline void set_cpu_numa_mem(int cpu, int node)
{
    per_cpu(_numa_mem_, cpu) = node; 
}                                                                                                                                  
#endif

file_one&file_two导致如果没有定义宏 CONFIG_NUMA 或者没有定义宏 CONFIG_HAVE_MEMORYLESS_NODES,则使用set_cpu_numa_mem处为空,否则调用同名函数set_cpu_numa_mem。

 

看如下两个文件

right.c:

include <stdio.h>

void A(int a)
{
    printf("%d\n", a);
}

#ifndef A
#warning "notdef A"
#define A
#else
#warning "def A"
#endif

#ifndef A
#warning "notdef A"
#else
#warning "def A"
#endif

int main(void)
{
    A(1);
    return 0;
}

gcc -E right.c -o right.i

 

wrong.c:

#include <stdio.h>

#ifndef A
#warning "notdef A"
#define A(cpu)
#else
#warning "def A"
#endif

#ifndef A
#warning "notdef A"
#else
#warning "def A"
#endif

void A(int a)
{
    printf("%d\n", a);
}

int main(void)
{
    A(1);   
    return 0;
}

 

posted on 2014-11-29 23:58  阿加  阅读(281)  评论(0)    收藏  举报

导航