c-preprocessor

What do 0x0040 and pipe sign denote here?

我们两清 提交于 2019-12-13 20:28:38
问题 Here SIMPLE_EX2 is being ORed with 0x0040 and the whole this providing as an address to SIMPLE_EX1. Is my understanding correct? #define SIMPLE_EX1 (0x0040 | SIMPLE_EX2) 回答1: | is not a pipe sign in C. It's a bit-wise or. So this expression: 0x0040 | SIMPLE_EX2 Simply gets the value of SIMPLE_EX2 and sets it's 7 th bit (from right) to 1. Unlikely, but note that if SIMPLE_EX2 itself is an expression with an operator that has lower precedence than | , the overall expression may be interpreted

Pre-processor macro to convert an hex string to a byte array

喜夏-厌秋 提交于 2019-12-13 14:50:26
问题 I've defined an AES-128 key as a build symbol inside my IDE, so that it calls GCC like this: arm-none-eabi-gcc -D"AES_KEY=3B7116E69E222295163FF1CAA1681FAC" ... (which is equivalent to #define AES_KEY 3B7116E69E222295163FF1CAA1681FAC ) The advantage is that the same symbol can also be passed automatically as a parameter to a post-build CLI script that encrypts the compiled code with this key (e.g. for a secure firmware update)... But how to store this key as a byte array in my code? I would

-D option is expanded incorrectly from g++ command line

倖福魔咒の 提交于 2019-12-13 14:39:23
问题 In C++ CodeBlocks project I added the following definitions to the project settings, compiler settings, #define: _DEBUG DATA_DIR=\"/media/Shared/SiX/Data\" This produces the following g++ command line: g++ -Wall -g -fPIC -save-temps -D_DEBUG -DDATA_DIR=\"/media/Shared/SiX/Data\" -I../Includes -c /media/Shared/SiX/SiXConfiguration/PathManager.cpp -o obj/Debug/PathManager.o This code does not compile: char* commonDataDir; #ifdef DATA_DIR commonDataDir = DATA_DIR; #endif Looking at preprocessor

Can the C preprocessor perform arithmetic and if so, how?

我是研究僧i 提交于 2019-12-13 14:25:34
问题 I'm currently writing code for a microcontroller; since the ATMega128 does not have a hardware multiplier or divider, these operations must be done in software and they take up a decent amount of cycles. However, for code portability and ease of use, I'd prefer not to hard-code precomputed values into my code So for instance, I have a number of tasks which are dependent on the system clock frequency. Currently I' running at 16MHz, but should I choose to lower that, say to reduce power

Error: no such file or directory - C

旧时模样 提交于 2019-12-13 14:07:51
问题 After interpreting this comment, /***************** arrayImpl.c **************/ #include"list/list.h" #if defined(ARRAY) .... #endif I wrote #include"list/list.h" in ./Computing/list/arrayImpl.c for testing Computing/list ADT using Computing/testList.c program, shown here. But list/list.h could not be found by list/arrayImpl.c , as shown below, PC ~/code_practice/Computing $ gcc -Wall -g -DARRAY ./list/*.c testList.c -o testList ./list/arrayImpl.c:3:22: fatal error: list/list.h: No such file

C++ Macro with Memory

旧时模样 提交于 2019-12-13 13:42:52
问题 This is originally posted as an answer to c++ macros with memory? But somehow I am not able to get this compiled. I might be missing something here. (I have a feeling that this is something C++ can do) main.cpp #include <iostream> using namespace std; const char * hello = "hello"; const char * world = "world"; #define VAR #define MEMORIZE world #include "memorize.h" #define MEMORIZE hello #include "memorize.h" int main() { cout << VAR << endl; return 0; } memorize.h #undef VAR #ifndef

How do I concatenate two macros with a dot between them without inserting spaces?

久未见 提交于 2019-12-13 12:38:08
问题 I'm preprocessing my InfoPlist file to include my revision number. My header looks like this: #import "svn.h" #define APP_VERSION 1.0 #define APP_BUILD APP_VERSION.SVN_REVISION When I check my build version from within the program, it's 1.0 . 123456 . But if I try this: #import "svn.h" #define APP_VERSION 1.0 #define APP_BUILD APP_VERSION ## . ## SVN_REVISION I get error: pasting formed 'APP_VERSION.', an invalid preprocessing token error: pasting formed '.SVN_REVISION', an invalid

What preprocessor define does -fopenmp provide?

若如初见. 提交于 2019-12-13 12:31:26
问题 I've got some code that can run with (or without) OpenMP - it depends on how the user sets up the makefile. If they want to run with OpenMP, then they just add -fopenmp to CFLAGS and CXXFLAGS . I'm trying to determine what preprocessor macro I can use to tell when -fopenmp is in effect. The omp.h header does not look very interesting: $ cat /usr/lib/gcc/x86_64-linux-gnu/4.8/include/omp.h | grep define #define OMP_H 1 #define _LIBGOMP_OMP_LOCK_DEFINED 1 # define __GOMP_NOTHROW throw () #

When will this execute?

浪子不回头ぞ 提交于 2019-12-13 10:13:47
问题 I have a C code: ... void caller() { #define YES 1 #define NO 0 } ... Will the both #define lines execute when caller is called/executed, or will they execute at compile-time only. 回答1: The prerpcessor macros don't execute, they are just named fragments of the code which will be replaced by the preprocessor to theirs content if you use them. Read more about preprocessor macros here. So, after preprocessing, your code will be: void caller() { } Let assume you use the YES macro after you

How does C++ preprocessor work?

守給你的承諾、 提交于 2019-12-13 09:59:23
问题 I am reading the book "C++ Primer" 5th Edition and I read that the preprocessor is a program that runs before the C++ compiler and replaces the #include, #define and #ifdefs and others with the appropriate content and then transfer control over to the compiler. But I came across a way in cl.exe (Microsoft Compiler) to view the preprocessor output saved directly to file. I did it, and when I opened the preprocessor output file I was surprised because I did not find what I expected! They were