Tag:

大多数嵌入式C编译器如何定义内存映射I / O的符号?

我经常写这样的内存映射I / O引脚 P3OUT |= BIT1; 我以为我的预处理器正在用这样的东西替换P3OUT: *((unsigned short *) 0x0222u) 但我今天挖了一个H文件,看到了这些内容: volatile unsigned short P3OUT @ 0x0222u; 在此之前还有一些扩展,但通常是这样。 正在使用符号’@’。 除此之外,还有一些关于使用扩展的C语言集的#pragma。 我假设这是链接器的某种指令,并且有效地将符号定义为存储器映射中的该位置。 我的假设是否适合大多数编译器的大部分时间? 这种方式或其他方面有关系吗? 那个@符号来自哪里,它是某种标准吗? 我正在使用IAR Embedded工作台。 这个问题类似于这个问题: 如何将变量放在内存中的给定绝对地址(使用GCC) 。 它符合我认为编译器正在做的事情。

使用include宏展开定义宏

我正在尝试定义一个宏。 这个想法是,当它扩展时,它将包括一个标题。 例如: #define function() \ include 非常感谢。

使用varidic宏时,获取“错误:#28:表达式必须具有常量值”

我正在从事硬件编程。 我创建了下面的Varidic宏。 #define UPDATE_DATA(bit,…) { \ do { \ int i; \ int j = 0; \ int _args[] = {__VA_ARGS__};\ int *addr = (int *) ADDR ; \ for (i = 0; i < (sizeof(_args)/sizeof(_args[0])); i++) {\ *(int *) (DATA_ADDR – j) |= _args[i];\ j = j + 0x4; \ }\ *addr |= 1 […]

如何将变量参数Functioncall作为宏定义?

想象一下,我有一个调试源文件,如下所示: #if _OWN_DEBUG_LEVEL != 0 void DebugLogMsg (DebugStruct_t *DebugStruct, size_t sizeID, char const *szFormat, …); #else #define DebugLogMsg(_Expression1, _Expression2, _Expression3) ((void)0) #endif 在这种情况下,我并不真正关心函数的其他参数,但是这个案例呢? #if _OWN_DEBUG_LEVEL > 0 #undef DebugLogMsg1 #define DebugLogMsg1(_Expression1, _Expression2, _Expression3) \ DebugLogMsg(_Expression1, _Expression2, _Expression3) #endif 在这种情况下,我不太确定…当我像这样调用宏时: DebugLogMsg1(pointer, var, pointer, 1, 2, 3); 将_Expression3视为pointer, 1, 2, 3或什么是确切的行为?

如何访问由宏定义隐藏的全局变量?

是否可以访问已在(自引用)宏中使用的全局范围的变量? 我正在使用用于指代此类宏的术语。 请参阅gcc.gnu.org/onlinedocs/cpp/Self-Referential-Macros.html 我的示例代码基于那里显示的示例代码。 简单示例: #include int foo = 10; /*A variable at global scope. There may be a few of these.*/ #define foo (4 + foo) /*A self-referential macro. There may be a few of these.*/ int main() { printf(“foo = %d\n”, foo); /*Prints 14. The value after the macro expansion */ /*Is there […]

C预处理器宏 – 基于参数连接的条件

我需要有关宏的帮助! 假设我已经定义了以下常量 #define foo_tacos_tuesday 1 #define foo_tacos 1 #define foo_nachos_wednesday 2 #define foo_nachos 3 我想编写一个执行以下操作的宏 #define MyFancyMacro( arg1, arg2 ) \ #if ( foo_ ## arg1 ## _ ## arg2 != foo_ ## arg1 ) \ foo_ ## arg1 ## _ ## arg2, foo_ ## arg1, 所以我可以设置一个只映射不匹配值的映射表: static const int mappingTable[] = { MyFancyMacro(tacos, tuesday) […]

如何将具有数组的宏字符串化为#define a_macro {5,7,7,97}?

请仔细检查。 #define _VERSION_ 1.4 #define DEFAULT_NETWORK_TOKEN_KEY { 3, 6, 5, 100} //我无法更改上面的宏但在下面 #define STR_VALUE(arg) #arg #define FUNCTION_NAME(name) STR_VALUE(name\r) #define TEST_FUNC #AP started v _VERSION_ #define TEST_FUNC_NAME FUNCTION_NAME(TEST_FUNC) #define QUOTE_X(t)#t #define QUOTE(t)QUOTE_X(t) #define ABC 100 //{ 3, 6, 5, 100} #define MYSTR “The value of ABC is” const uint8 startMsg[] = MYSTR ” ” QUOTE(ABC); 结果: […]

奇怪的宏定义问题

我想在编译时根据另一个宏的值定义一个宏。 但是,此代码未按预期执行: #include #include #include #define SIXTEEN 16 #define TWO (SIXTEEN % 8 == 0)? (SIXTEEN / 8) : ((SIXTEEN / 8) + 1) int main(); int main() { printf(“max = %d\n”, TWO); int i; for (i = 0; i < TWO; i++) { printf("%d\n", i); } return 0; } 这打印: max = 2 0 […]

使用C宏包装函数(使用重命名)

我正在尝试使用宏来定义一个函数,它实际上将现有函数包装到带有前缀的另一个函数中。 比方说吧: int f1(int a, void *b, char c) { return 1; } int f2(void *a) { return 1; } void f3(void *a, int b) {} void f4() {} #define WRAP(prefix, f) // do something WRAP(a, f1) or WRAP(a,f1,int,void*,char) or WRAP(a,f1,int,a,void*,b,char,c) 这应该产生类似的东西: int a_f1(int a, void *b, char c); int a_f1(int a, void *b, char […]

在C中取消定义类似函数的宏?

我试图对glibc做一些黑客攻击,我想知道是否有可能重新定义类似函数的宏? 例如, 具有以下宏: #define expm1(Val) __TGMATH_UNARY_REAL_ONLY (Val, expm1) 如何将expm1重新定义为: #define expm1(Val) __TGMATH_UNARY_REAL_IMAG (Val, expm1, cexpm1) 我想我必须取消之前的定义,但我不知道该怎么做。