c-preprocessor

How to access C preprocessor constants in assembly?

感情迁移 提交于 2019-12-21 19:12:03
问题 If I define a constant in my C .h file: #define constant 1 How do I access it in my assembly .s file? 回答1: If you use the GNU toolchain, gcc will by default run the preprocessor on files with the .S extension (uppercase 'S'). So you can use all cpp features in your assembly file. There are some caveats: there might be differences in the way the assembler and the preprocessor tokenize the input. If you #include header files, they should only contain preprocessor directives, not C stuff like

How to access C preprocessor constants in assembly?

谁说胖子不能爱 提交于 2019-12-21 19:11:06
问题 If I define a constant in my C .h file: #define constant 1 How do I access it in my assembly .s file? 回答1: If you use the GNU toolchain, gcc will by default run the preprocessor on files with the .S extension (uppercase 'S'). So you can use all cpp features in your assembly file. There are some caveats: there might be differences in the way the assembler and the preprocessor tokenize the input. If you #include header files, they should only contain preprocessor directives, not C stuff like

#define vs. enums for addressing peripherals

北慕城南 提交于 2019-12-21 12:35:56
问题 I have to program peripheral registers in an ARM9-based microcontroller. For instance, for the USART, I store the relevant memory addresses in an enum : enum USART { US_BASE = (int) 0xFFFC4000, US_BRGR = US_BASE + 0x16, //... }; Then, I use pointers in a function to initialize the registers: void init_usart (void) { vuint* pBRGR = (vuint*) US_BRGR; *pBRGR = 0x030C; //... } But my teacher says I'd better use #define s, such as: #define US_BASE (0xFFFC4000) #define US_BRGR (US_BASE + 0x16)

Can I define variadic C preprocessor macros with __VA_ARGS in the middle instead of the end?

我怕爱的太早我们不能终老 提交于 2019-12-21 12:08:59
问题 GCC complains if I do this: #define M(obj,met, ..., contents) obj##_##met(const void * self, __VA_ARGS__) { \ contents \ } Giving me these 2 reasons: error: missing ')' in macro parameter list warning: __VA_ARGS__ can only appear in the expansion of a C99 variadic macro Apparently, C99 - style variadic macros expect the closing parenthesis immediately after the ellipsis, effectively demanding that the variadic list be the last arguments of the macro. I need it to be in the middle to produce

Preprocessor-aware code navigation in IDE for C project

天大地大妈咪最大 提交于 2019-12-21 11:58:52
问题 Background I spend a lot of time navigating and editing convoluted scientific C codes. Usually they contain hundreds of optional features switched on and off with preprocessor directives. This makes it almost impossible to say at a glance whether the current block of code is activated in my current setup or not. The code itself does not help as every feature is smudged all over the place and everything is usually done using global variables. Question Is there an IDE that can handle

What does #line mean?

爱⌒轻易说出口 提交于 2019-12-21 07:10:55
问题 What does the following line do? #line 25 "CSSGrammar.y" And what's with the extension? 回答1: According to the Standard: §16.4.3: A preprocessing directive of the form # line digit-sequence new-line causes the implementation to behave as if the following sequence of source lines begins with a source line that has a line number as specified by the digit sequence (interpreted as a decimal integer). If the digit sequence specifies zero or a number greater than 2147483647, the behavior is

Why no warning with “#if X” when X undefined?

烈酒焚心 提交于 2019-12-21 06:55:35
问题 I occasionally write code something like this: // file1.cpp #define DO_THIS 1 #if DO_THIS // stuff #endif During the code development I may switch the definition of DO_THIS between 0 and 1. Recently I had to rearrange my source code and copy some code from one file to another. But I found that I had made a mistake and the two parts had become separated like so: // file1.cpp #define DO_THIS 1 and // file2.cpp #if DO_THIS // stuff #endif Obviously I fixed the error, but then thought to myself,

Objective C “#if” syntax

让人想犯罪 __ 提交于 2019-12-21 03:19:15
问题 I'm a little confused by the "pound if" or #if syntax I see when I look at some classes. For example: #if someConstant == someNumber do something #elif etc versus: if (someConstant == someNumber) do something else if { do more stuff } what's the difference, and why use #if ? 回答1: #if etc are preprocessor directives. This means that they are dealt with before compiling and not at runtime. This can be useful, for example, in defining debugging behaviour that only compiles when you build for

CUDA compiler (nvcc) macro

你离开我真会死。 提交于 2019-12-20 20:03:38
问题 Is there a #define compiler (nvcc) macro of CUDA which I can use? (Like _WIN32 for Windows and so on.) I need this for header code that will be common between nvcc and VC++ compilers. I know I can go ahead and define my own and pass it as an argument to the nvcc compiler (-D), but it would be great if there is one already defined. 回答1: __CUDACC__ I don't think it will be that trivial. Check the following thread http://forums.nvidia.com/index.php?showtopic=32369&st=0&p=179913&#entry179913 回答2:

Convert string from __DATE__ into a time_t

给你一囗甜甜゛ 提交于 2019-12-20 18:46:10
问题 I'm trying to convert the string produced from the __DATE__ macro into a time_t . I don't need a full-blown date/time parser, something that only handles the format of the __DATE__ macro would be great. A preprocessor method would be nifty, but a function would work just as well. If it's relevant, I'm using MSVC. 回答1: Edit: the corrected function should look something like this: time_t cvt_TIME(char const *time) { char s_month[5]; int month, day, year; struct tm t = {0}; static const char