question for #define experts

 

Hi all!

Is there any way to get a closing bracket from #define?

#define  LPE );
#define  LP Print( LPE
void OnStart()
  {
   LP "myMessage"
  }
 
What's the point? To avoid writing parentheses? Is that a big problem?
 
Dmitry Fedoseev:
What's the point? So you don't have to write parentheses? Is it a big problem?


#define  LPRINT_END , __FUNCSIG__);
#define  LPRINT gFactory.getCLogManager().doPrint (

and in the middle is a log message

LPRINT "abnormal situation, couldn't select position", ENUM_LOG_LEAD_DEBUG

without the closing.

LPRINT (FUNCSIG, "abnormal situation, couldn't select position", ENUM_LOG_LEAD_DEBUG);

either the beginning (FUNCSIG to #define and then a parenthesis at the end

 
What's the point? So you don't have to write parentheses when calling a macro?
 
Dmitry Fedoseev:
What's the point? So you don't have to write parentheses when calling the macro?

let's say we want to add __FUNCSIG__ and ErrorLast to a macro. When the macro is called, there will be one closing parenthesis on the line with its code. So, yes, a thought flashed around, is there any way this could be improved

 
Nikolai Karetnikov:

let's say we want to add __FUNCSIG__ and ErrorLast to a macro. When the macro is called, there will be one closing parenthesis on the line with its code. So, yes a thought flashed around, is there any way this could be improved

Is there no way to answer my question?

Maybe just use macros normally? Unless, of course, your hands fall off two parentheses.

#define  LP(X) Print(X)
void OnStart()
  {
   LP("myMessage");
  }
 
Dmitry Fedoseev:

Is there no way to answer my question?

Can't you just use macros properly? Unless, of course, your hands fall off two parentheses.

I should have read about parameters, yes )

Thank you!

 

In general, this is how it's solved:

#define  LOG_S(dText) (SLog(__FUNCSIG__,__FILE__,__LINE__,dText)).Log()
#define  LOG_C(dText) CLog::Get().Log(__FUNCSIG__,__FILE__,__LINE__,dText)
#define  LOG_F(dText) Log(__FUNCSIG__,__FILE__,__LINE__,dText)

struct SLog{
   string cText;
   SLog(string mFunc,string mFile,int mLine,string mText):
      cText(StringFormat("%s, %s, line %i, %s",mFunc,mFile,mLine,mText)){}
   void Log() {Print(cText);}
};

class CLog{
   CLog(){}
public:
   static CLog* Get(){
      static CLog instance;
      return &instance;}
   void Log(string mFunc,string mFile,int mLine,string mText) {PrintFormat("%s, %s, line %i, %s",mFunc,mFile,mLine,mText);}
};

void Log(string mFunc,string mFile,int mLine,string mText) {PrintFormat("%s, %s, line %i, %s",mFunc,mFile,mLine,mText);}


void OnStart(void)
  {
  LOG_S("struct");
  LOG_C("class");
  LOG_F("func");
  }

Three options: temporary object, singletone, function - whichever is more religious.) In terms of speed, they are practically indistinguishable.

 
#define  LOG(dText) printf("%s, %s, line %i, %s",__FUNCSIG__,__FILE__,__LINE__,dText);

void OnStart(void){
  LOG("bezgovna");
}
But unfortunately, you won't impress the suckers.
 
Dmitry Fedoseev:
But, unfortunately, you don't impress suckers.

Why didn't you show this solution to the man straight away?)

UPD: bezgovna - spelled no sh..t ))))
 
Vladimir Simakov:

Why didn't you show this solution to the man straight away?)

UPD: bezgovna - spelled no sh..t )))

Thank you! )

Essentially.

I stopped at the variant with the class. Even such elementary things as #define parameterization are quickly forgotten without daily use.

On nerves.

God, how sensitive everybody is here; you may ask a question without an implication, without the intent to offend or insult, but no, somewhere in the soul of an unrecognized genius you get a nagging and a desire to assert yourself at the expense of yet another amateur. I do not encounter it on the English forum, although I write there regularly. Realizing this, I usually try not to react to such remarks, but if Dmitry, you want to frolic in a verbal battle, I will give you pleasure by plunging you headfirst into your own emanations.