c++ - What does ## (double hash) do in a preprocessor directive? -


#define define_stat(stat) \ struct fthreadsafestaticstat<fstat_##stat> statptr_##stat; 

the above line take unreal 4, , know ask on over unreal forums, think general c++ question warrants being asked here.

i understand first line defines macro, not versed in preprocessor shenanigans in c++ , i'm lost on there. logic tells me backslash means declaration continues onto next line.

fthreadsafestaticstat looks bit template, there's #'s going on in there , syntax i've never seen before in c++

could tell me means? understand may not have access unreal 4, it's syntax don't understand.

## preprocessor operator concatenation.

so if use

define_stat(foo)

anywhere in code, gets replaced with

struct fthreadsafestaticstat<fstat_foo> statptr_foo;

before code compiled.

here example a blog post of mine explain further.

#include <stdio.h>  #define decode(s,t,u,m,p,e,d) m ## s ## u ## t #define begin decode(a,n,i,m,a,t,e)  int begin() {     printf("stumped?\n"); } 

this program compile , execute successfully, , produce following output:

stumped? 

when preprocessor works on code,

  • begin() replaced decode(a,n,i,m,a,t,e)()
  • decode(a,n,i,m,a,t,e)() replaced m ## ## ## n()
  • m ## ## ## n() replaced main()

thus effectively, begin() replaced main().


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -