Errors, bugs, questions - page 2865

 

It's not possible to create a new product for the marketplace, it says error 500.

The product has been created and checked, it says it's been published, but when you click on the link you get an answer of 500.

 
fxsaber:

Works top-down as a text replacement. I.e. "TMP" will be replaced by "VALUE".

Vladimir Simakov:

This is not a compiler - it's a preprocessor)

turns into

, and the VALUE is not defined.

How is undef supposed to work?

 
Andrey Khatimlianskii:

How is undef supposed to work?

Up to this point, there is "text replacement" going on.

 
Vladimir Simakov:

It's not a compiler - it's a preprocessor)

turns into

and the VALUE is undefined.

#define  VALUE (VALUE*2)

I understand correctly, the VALUE*2 value type is const and is tied to the substitution itself, i.e. the VALUE is also a constant. The compiler creates two constants.

If so, it must be creating a new substitution.

#define  VALUE1 (VALUE*2)
#define  VALUE VALUE1

And it's not correct if VALUE above the code was defined as a constant.

 
fxsaber:

Up to this point there is "text replacement" going on.

Doesn't match, changes TMP toVALUE in line "#define VALUE (TMP*2)" which is after.

 
Andrey Khatimlianskii:

Doesn't add up, changes TMP toVALUE in line "#define VALUE (TMP*2)" which is after.

#define  MACROS TEXT
 // В этом интервале везде идет замена в исходнике MACROS на TEXT, как делалось бы в текстовом редакторе.
#undef  MACROS
And so goes the substitution until all substitutions are complete.
 
fxsaber:
And so the substitutions go on and on until they all end.

There is code:

#define  VALUE 10       // 
#define  TMP VALUE      // 
#undef  VALUE           // 
#define  VALUE (TMP*2)  // 

The first substitution changes the VALUE to 10 throughout the code up to #undef VALUE, leaving this:

#define  TMP 10
#define  VALUE (TMP*2)

The next substitution changes the TMP to 10. It turns out

#define  VALUE (10*2)

Where am I going wrong?

 
Andrey Khatimlianskii:

There is code:

The first substitution changes the VALUE to 10 throughout the code up to #undef VALUE, leaving this:

The next substitution changes the TMP to 10. It turns out

What am I doing wrong?

It's not 10 which is substituted for TMP, it's the VALUE, but if the VALUE is defined (which is a pain in the ass), it's 10.

Watch this step by step:

#define  VALUE 10        
#define  TMP VALUE       
#undef  VALUE            
#define  VALUE (TMP*2)

void OnStart(void)
{
   Print(VALUE)
}

The preprocessor faithfully inserts Print

Print((TMP*2));

and then, again with no trickery, substitutes what? Right:

Print((VALUE*2));

and then it erases all the preprocessor's directives and only after that the compiler gets this:

void OnStart(void)
{
   Print((VALUE*2));
}
 
Vladimir Simakov:

TMP is not 10, but VALUE is substituted for TMP, and then if VALUE is defined (which is a problem), it is 10

Watch this step by step:

The preprocessor faithfully inserts Print

and then, again with no trickery, substitutes what? Right:

and then it erases all the preprocessor's directives and only after that the compiler gets this:

This is not called "top-down".

 
Andrey Khatimlianskii:

It's not called top-down.

Sorry, I got confused while trying to explain myself)))

One more time:

#define  VALUE 10        
#define  TMP VALUE       
#undef  VALUE            
#define  VALUE (TMP*2)

At the time of the second VALUE definition, the VALUE macro is not defined, so VALUE is defined as

(VALUE*2)

, because TMP was and still is defined by VALUE.

But TMP, after the second VALUE definition, is expanded to

(TMP*2)

(Something like this))

The preprocessor just fills in what it has and it doesn't matter how and where it is defined. This is why you have to be careful with it. Example:

#define  min(A,B) ((A)<(B)?(A):(B))

long Foo(int x) {return x*x;}

void OnStart(void)
{
   int a=500,
       b=20;
   Print(min(500,Foo(b))); //400
}

, and now let's add an evil thing to the function, namely a side effect

#define  min(A,B) ((A)<(B)?(A):(B))

long Foo(int x){
   Print("Увидивший это второй раз - нубяра vulgaris");
   return x*x;}

void OnStart(void)
{
   int a=500,
       b=20;
   Print(min(500,Foo(b)));
}

And this is just an inscription, but what if the deposit depends on this function?

Reason: