predefined-macro

Detecting Aligned Memory requirement on target CPU

允我心安 提交于 2019-12-06 06:48:33
问题 I'm currently trying to build a code which is supposed to work on a wide range of machines, from handheld pockets and sensors to big servers in data centers. One of the (many) differences between these architectures is the requirement for aligned memory access. Aligned memory access is not required on "standard" x86 CPU, but many other CPU need it and produce an exception if the rule is not respected. Up to now, i've been dealing with it by forcing the compiler to be cautious on specific data

Detecting Aligned Memory requirement on target CPU

三世轮回 提交于 2019-12-04 12:39:29
I'm currently trying to build a code which is supposed to work on a wide range of machines, from handheld pockets and sensors to big servers in data centers. One of the (many) differences between these architectures is the requirement for aligned memory access. Aligned memory access is not required on "standard" x86 CPU, but many other CPU need it and produce an exception if the rule is not respected. Up to now, i've been dealing with it by forcing the compiler to be cautious on specific data accesses which are known to be risky, using the packed attribute (or pragma). And it works fine. The

Why would __FUNCTION__ be undefined?

ぃ、小莉子 提交于 2019-12-02 12:13:25
问题 I have a C++ library that uses the predefined macro __FUNCTION__ , by way of crtdefs.h. The macro is documented here. Here is my usage: my.cpp #include <crtdefs.h> ... void f() { L(__FUNCTIONW__ L" : A diagnostic message"); } static void L(const wchar_t* format, ...) { const size_t BUFFERLENGTH = 1024; wchar_t buf[BUFFERLENGTH] = { 0 }; va_list args; va_start(args, format); int count = _vsnwprintf_s(buf, BUFFERLENGTH, _TRUNCATE, format, args); va_end(args); if (count != 0) { OutputDebugString

Why would __FUNCTION__ be undefined?

风格不统一 提交于 2019-12-02 05:50:18
I have a C++ library that uses the predefined macro __FUNCTION__ , by way of crtdefs.h. The macro is documented here . Here is my usage: my.cpp #include <crtdefs.h> ... void f() { L(__FUNCTIONW__ L" : A diagnostic message"); } static void L(const wchar_t* format, ...) { const size_t BUFFERLENGTH = 1024; wchar_t buf[BUFFERLENGTH] = { 0 }; va_list args; va_start(args, format); int count = _vsnwprintf_s(buf, BUFFERLENGTH, _TRUNCATE, format, args); va_end(args); if (count != 0) { OutputDebugString(buf); } } crtdefs.h #define __FUNCTIONW__ _STR2WSTR(__FUNCTION__) The library (which is compiled as a

How can I write a 'clamp' / 'clip' / 'bound' macro for returning a value in a given range?

て烟熏妆下的殇ゞ 提交于 2019-11-29 04:06:24
I often find myself writing something like int computedValue = ...; return MAX(0, MIN(5, computedValue)); I would like to be able to write this as a single one-line macro. It must be free of side effects, in the same way that the existing system macros MIN and MAX are, and should work for the same data types as MIN and MAX. Can anyone show me how to turn this into a single macro? This is without side effects and works for any primitive number: #define MIN(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; }) #define MAX(A,B) ({ __typeof__(A) __a = (A); __typeof__

How to use __DATE__ and __TIME__ predefined macros in as two integers, then stringify?

痞子三分冷 提交于 2019-11-28 15:54:06
Want to use __ DATE __ and __ TIME __ as integer for giving automated version to my code in compile time. #define STRINGIZER(arg) #arg #define STR_VALUE(arg) STRINGIZER(arg) #define DATE_as_int_str useD(__DATE__) // What can be done ? #define TIME_as_int_str useT(__TIME__) // What can be done ? #define VERSION 1.4 #define COMPLETE_VERSION STR_VALUE(VERSION) "." DATE_as_int_str "." TIME_as_int_str and get COMPLETE_VERSION as string in a const unsigned char [] . const unsigned char completeVersion[] = ?? COMPLETE_VERSION; Should output 1.4.1432.2234 something. One of the possible solution could

How to use __DATE__ and __TIME__ predefined macros in as two integers, then stringify?

吃可爱长大的小学妹 提交于 2019-11-27 09:22:41
问题 Want to use __ DATE __ and __ TIME __ as integer for giving automated version to my code in compile time. #define STRINGIZER(arg) #arg #define STR_VALUE(arg) STRINGIZER(arg) #define DATE_as_int_str useD(__DATE__) // What can be done ? #define TIME_as_int_str useT(__TIME__) // What can be done ? #define VERSION 1.4 #define COMPLETE_VERSION STR_VALUE(VERSION) "." DATE_as_int_str "." TIME_as_int_str and get COMPLETE_VERSION as string in a const unsigned char [] . const unsigned char