Category : macros

I am using c++,gcc. I have code for logging with macro like this: #define E_DEBUG(level, …) if (err_get_debug_level() >= level) err_msg(ERR_DEBUG, FILELINE, __VA_OPT__) #define ERR_DEBUG 1 #define FILELINE __FILE__ , __LINE__ int err_get_debug_level(void); void err_msg(int lvl, const char *path, long ln, const char *fmt, …); int main ( void ) { E_DEBUG(1,("%d",14)); } The code ..

Read more

In https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/TensorAdvancedIndexing.cpp#L817, the 6-th argument is a lambda function. In the definition of the macro in https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/Dispatch.h#L717, I am not seeing how the input lambda function is used since __VA_ARGS__ isn’t used in the macro definition. I added some print statements into the input lambda and nothing is printing when I execute this code, which ..

Read more

This is related to the problem: How to get the caller's class name inside a function without passing it as a parameter? Initial Goal: I want to capture the class name (class type) inside a template function without passing the class name(string) as parameter. Solution: I used std::remove_reference_t<decltype(*this)> in my template function so that my ..

Read more

I was trying to handle different line-ending. But as I expected the output was different than expected. test4utf8mac.srt is a subtitle file of SubRip format having line-ending of the CR type(i.e ‘r’). #include<iostream> #include<fstream> #include<string> using namespace std; int32_t main() { #define NLINE "Default" string str; string delimiter; std::ifstream chk("./srt/test4utf8mac.srt",ios::binary); if(!chk.is_open()) { cout<<"file not opened"<<endl; ..

Read more

I am using VSCode. All following description happens on VSCode env. I got one header with namespace "Loki" defined which is called "Typelist.h" I am trying to use a struct inside this namespace defined in this header. I did: # define LOKI_TYPELIST_1(T1) ::Loki::TypeList<T1, ::Loki::NullType> # define LOKI_TYPELIST_2(T1, T2) ::Loki::TypeList<T1, LOKI_TYPELIST_1(T2)> Normally, I think it should ..

Read more

I’m working with WPP (Windows Tracing) and the basic macro looks like this: trace(SEVERITY, SOURCE, "%s started", app_name); I would like to do is something like this but I get a variety of compiler/trace errors: #define trace_with_console(__level, __flags, __format, …) do { printf(__format, __VA_ARGS__); trace(__level, __flags, __format, …); } while (false); Is there a correct ..

Read more