preprocessor-directive

Always same effect of #pragma pack(16) and #pragma pack(8)?

痴心易碎 提交于 2019-12-23 22:52:06
问题 I am trying to align data members by using #pragma pack (n). Take the following as an example: #include <iostream> using namespace std; #pragma pack(8) // or (16) struct A { int a; char b; char c; char d; char e; char f; double g; }; int main() { cout << sizeof(A) << endl; return 0; } Both will print 24 for #pragma pack(8) and #pragma pack(16) . I can understand the result for n=8 with the data alignment, of my understanding, as follows: Bytes: |1 2 3 4|5|6|7|8|9|10 11 12 13 14 15 16|17 18 19

Preprocessor directives

こ雲淡風輕ζ 提交于 2019-12-23 14:25:05
问题 When we see #include <iostream> , it is said to be a preprocessor directive . #include ---> directive And, I think: <iostream> ---> preprocessor But, what is meant by "preprocessor" and "directive"? 回答1: It may help to think of the relationship between a "directive" and being "given directions" (i.e. orders). "preprocessor directives" are directions to the preprocessor about changes it should make to the code before the later stages of compilation kick in. But, what's the preprocessor? Well,

check if uint64_t is defined

北城余情 提交于 2019-12-23 10:14:30
问题 The type uint64_t is not guaranteed to be defined on 32-bit platforms, and code like int main() { uint64_t i = 0; } may result in compilation errors of the type incomplete type . Is there a preprocessor directive to check if uint64_t is present? Any other way for checking if the type is defined? 回答1: I think that reasonable approach is to check if associated macro UINT64_MAX is defined, e.g. #include <cstdint> /* don't forget to include */ ... #ifdef UINT64_MAX ... #endif AFAIK you can't

How can I programmatically force the compiler to stop the compilation process after it encountered a user created error?

北城余情 提交于 2019-12-23 02:05:45
问题 In my code I am using the #error preprocessor directive in order to create an error. However, it still continues the building process. How can I force the building process programmatically to stop after encountering my error? I am using Microsoft Visual Studio 2015, C++ v140, x86, for Windows 10. 回答1: From MSDN The #error directive emits a user-specified error message at compile time and then terminates the compilation. (Emphasis Added) If compilation is continuing after the #error directive,

How can I programmatically force the compiler to stop the compilation process after it encountered a user created error?

限于喜欢 提交于 2019-12-23 02:05:15
问题 In my code I am using the #error preprocessor directive in order to create an error. However, it still continues the building process. How can I force the building process programmatically to stop after encountering my error? I am using Microsoft Visual Studio 2015, C++ v140, x86, for Windows 10. 回答1: From MSDN The #error directive emits a user-specified error message at compile time and then terminates the compilation. (Emphasis Added) If compilation is continuing after the #error directive,

Can you nest C preprocessor directives?

白昼怎懂夜的黑 提交于 2019-12-22 09:17:32
问题 For instance, is the following possible: #define definer(x) #define #x? 回答1: Though your syntax is invalid, the answer to your question is technically yes. But it can only be accomplished by nasty tricks that make your code unreadable and unmaintainable. See also: http://www.ioccc.org/years.html#1995_vanschnitz and http://www.ioccc.org/years.html#2004_vik2 回答2: No, you can't do that. The pound ( # ) symbol has a different meaning while in a definition. it means - if this is an argument, make

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

Are there C like pre-processor directives for Octave and Scilab to be used for intercompatible code?

我的梦境 提交于 2019-12-20 04:07:55
问题 In C / C++ languages one can use macros or as called "per-processor directives" to instruct the compiler how the code should be read. The simple commands of #def , #ifdef , #ifndef , #else , #endif ... give the compiler the ability to check for Operating system, compiler and other environment information. I know Octave and Scilab are interpreted languages, but I'm wondering if is there any way to tell the interpreter to replaces parts of script while loading it? For example can I write a code

Why would somebody use an #if 1 C preprocessor directive?

試著忘記壹切 提交于 2019-12-17 19:32:58
问题 I am looking through some C source code and I don't understand the following part #if 1 typedef unsigned short PronId; typedef unsigned short LMId; # define LM_NGRAM_INT #else typedef unsigned int LMId; typedef unsigned int PronId; # undef LM_NGRAM_INT #endif Why would someone do #if 1 ? Isn't it true that only the first block will ever be processed? 回答1: Yes.. Only the first block will be processed --- until someone changes the 1 to a 0. Then the other block will be compiled. This is a

Is there a preprocessor directive for detecting C++11x support? [duplicate]

末鹿安然 提交于 2019-12-17 17:59:42
问题 This question already has answers here : How do I check for C++11 support? (10 answers) Closed 5 years ago . If have some code where I would like to use C++11x extensions as much as possible, but have a fallback if this is not supported. Currently the OSX version of GCC and the VisualC compiler has little to no support for C++11x, so I use: #if (defined(__APPLE__) || (defined(_WIN32))) ...fallback code without C++11x ... #else ... code using C++11x ... #endif And this works, but is not really