@related : C C++ Programming MSVC

THE C PREPROCESSOR & ITS LANGUAGE

PREPROC

#define max2(a,b)  ( (a>b) ? a : b )
#define max3(a,b,c)  ( max2( (max2(a,b) , c ) )
#ifndef __cplusplus
#error A C++ compiler is required
#endif
printf("DATE=%s, TIME=%s\n", _ _ DATE _ _,  _ _ TIME _ _);
//Jun XX XXXX, 15:01:32
printf("FILE=%s, LINE=%d\n",  _ _ FILE _ _, _ _ LINE _ _ );
//main.cpp, line: 133
#define Str(x) #x
#define Xstr(x) Str(x)
#define OP plus
char *opname = Xstr(OP);
#define Paste(a, b) a##b

[[C++]] Wrap

#ifdef  __cplusplus
extern "C" {
#endif
/* ... C  code ... */
#ifdef  __cplusplus
} // extern "C"
#endif

[[MSVC]]

#ifdef _MSC_VER msvc-6.0 does declare var outside's for scope #define for if (true) for #endif _MSC_VER

USING C PREPROC AND C++ TEMPLATES

How to use C Preprocessor on some template parameter ?

I'm afraid C Preproc process before the C++ one … if we can say that

I needed a such thing to provide “switch on type facilities” :

#include <iostream>
#include <string>
using namespace std;
#define cdebug cout
/**
  * @author: www.philippe.COVAL.online.fr
  * PROJECT=preproc; make ${PROJECT} ; ./${PROJECT} ; rm ./${PROJECT}
  **/
#define STR(x) #x
template<class T>
class Cls {
public:
Cls(T* in=0) : ptr_(in) {    type_=STR(T);  }
T* ptr_;
char* type_;
};
int main(int argc, char* argv[[]]) {
cdebug<<STR(stringize)<<endl; // says "stringize" // ok
Cls<char> a;
cdebug<<a.type_<<endl; //says "T" and "char" was wanted //PB HERE
}

see typeid (T).name () or gcc typeof()

#include <iostream>
#include <string>
#include <typeinfo>
using namespace std;
#define cdebug cout
/**
  * @author: www.philippe.COVAL.online.fr
  * PROJECT=typeid; make ${PROJECT} ; ./${PROJECT} ; rm ./${PROJECT}
  **/
template<class T>
class Cls
{
public:
 Cls(T* in=0) : ptr_(in) {
  //type_= typeid(T); // how to use this ?
  type_name_= typeid(T).name();
}
type_info type_id() { return typeid(T); }
T* ptr_;
const char* type_name_;
//type_info type_; // how to use this ?
};
int main(int argc, char* argv[[]]) {
Cls<char> a;
cdebug<<a.type_name_<<endl; //says "c"
Cls<Cls<char> > b;
cdebug<<b.type_name_<<endl; //says "3ClsIcE"
if ( typeid(a) ==== typeid(b) ) { cdebug<<"differents"<<endl; } // ok diff===
//if ( a.type_id() ==== b.type_id() ) { cdebug<<"differents"<<endl; }===
//  switch ( typeid(a) ) {
//typeid.cpp:39: error: switch quantity not an integer
}

COMPILER SPECIFIC MACROS

See ProgrammingTools

  • gcc : _ _ GNUC _ _ _ _ PRETTY_FUNCTION _ _

_WIN32 _MSC_VER _MT _DLL _MFC_VER _CPPRTTI _CPPUNWIND _M_IX86

Java

MISC

preprocessor.txt · Last modified: 2012/11/04 21:04 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki