question for #define experts - page 3

 
Alexandr Andreev:


Everyone seems to understand.....

So this is for those who are just starting their way....

We can wrap it all in a stat class and return a reference, which then equalize the rest since this method has a minus when working with if (a!=5) Print(a); it will not work, you should always write if (a!=5) {Print(a);}, in classes we can correct this moment, but I'm too lazy)) and in general, it seems all is in the history archives

the way with classes, initialize our data via static method and combine the operator call our print.... thenif (a!=5) Print(a); , it will work

This is all from laziness. I got carried away, but I gave up. Reduced something, but to a reasonable. Besides prints, writing to file is either collecting data, or working out the algorithm, setting. And if you score predetermined thongs into the print, commas will print. All in all it trains the brain of course, but it doesn't even show the path.

 
Alexandr Andreev:



Dmitry Fedoseev:


Vladimir Simakov:


As it happens, may I ask you a question? What is the difference between a define and a function call for the compiler. I've come to the conclusion that it is not. Am I mistaken?

 
Valeriy Yastremskiy:

As it happens, may I ask you a question? What is the difference between a define and a function call for the compiler. I've come to the conclusion that it is not. Am I mistaken?

Define is a substitution during BEFORE compilation, so __LINE__ becomes exactly like it should be, you may substitute an incomplete code fragment.

And function is code reference (goto) in many languages and in others code substitution (unfolding all functions) at runtime.

And defy is kind of evil because it makes it harder to find bugs, so a good defy is when you don't have one
 
Alexandr Andreev:

Define - substitution at compile time, so __LINE__ becomes exactly as it should be, you can substitute incomplete code snippet

And function is code reference (goto) in many languages and in others code substitution (unfolding all functions) at runtime.

Question regarding MKL. I understand correctly there is no goto in the executable, except for loops. The question arose from the peculiarities of compilation. Strictly top down. And if a variable is declared at the bottom of the loop body, and called in the loop conditions there will be a warning. The output is checked from top to bottom. And the executable is generated by substituting functions as a define, not bygoto references.

 
Alexandr Andreev:

Define - substitution at compile time, so __LINE__ becomes exactly as it should be, you can substitute incomplete code snippet

A function in many languages is a reference to the code (goto), while in others code is substituted (unfolding all functions) at runtime.

So substitution affects only build speed at compile time?
Is it reasonable only for building large projects?
Or the defunct code will be executed faster in the executable?

 
Valeriy Yastremskiy:

The question is in relation to MKL. I understand correctly there is no goto in the executable, except for loops. The question arose from the peculiarities of compilation. Strictly top down. And if a variable is declared at the bottom of the loop body, and is called in the loop conditions there will be a warning. The output is checked from top to bottom. And the executable is generated by substituting functions as a define, not bygoto references.

No, mcl definitely used the code reference method in 2008.

Whether full unrolling is used now is not obvious.

Nowadays, writing your own compiler is 3-4 year in any computer science department,

Everything may be rather complicated there - there are references and de-folding, so one may write his or her code anyway he or she wants.

Most likely, they disclose what they can, but not everything. It is clear that operators like for, etc. are a different story.

 
Roman:

So substitution only affects build speed at compile time?
Is it reasonable only for building large projects?
Or the defunct code will still run faster in the executable?

Deployment of usual functions is by itself

i.e. for example for (int i=0; i<ArraiSize(max); i++)

here ArraiSize(max); will be expanded and it will get something like address to size of given array (if we look at array, it has its size in a variable, and here we get substitution for this variable "address in memory") i.e. there is no sense to change it to a variable by itself, at all

for (int i=0; i<ArraiSize(max); i++)

и

for (int i=0; i<size; i++)

In this case ArraiSize(max) and size have the same timings to determine the array's size value

 
Alexandr Andreev:

No, μl definitely used the code reference method in 2008.

Whether full unrolling is used now is not obvious.

Nowadays, writing your own compiler is the 3rd-4th year of any computer science department,

Everything may be rather complicated there - there are references and de-folding, so one may write his or her code anyway he or she wants.

Most likely, they disclose what they can, but not everything. It is clear that operators like for etc. are a totally different story.

Thank you. Judging by the ongoing topic Errors and Bugs, optimization is everything.... well, sort of evil leading to the light)))) eternal repair if the car is going this way too)

 
Roman:

So substitution only affects build speed at compile time?
Is it reasonable only for building large projects?
Or will the defunct code be executed faster in the executable?

1 - perhaps yes, but in microseconds =)

2 - rather the opposite - we should use the shortest defines and the minimum.

3 - in 2008 this statement would be true for µl4. But now the speed will be the same

 
Alexandr Andreev:

Deployment of normal functions is a matter of course

i.e. for example for (int i=0; i<ArraiSize(max); i++)

here ArraiSize(max); will be expanded and it will get something like address to size of given array (if we look at array, it has its size in a variable, and here we have substitution on this variable "address in memory") i.e. there is no sense to change it to a variable, at all

for (int i=0; i<ArraiSize(max); i++)

и

for (int i=0; i<size; i++)

In this case ArraiSize(max) and size have the same timings for determining the array's size value

In this sample loop, I think I disagree about the timings.
On the contrary, it is recommended to get the result in size variable, and use it in the condition.
The reason is that at each iteration forArraiSize(max), the loop will unwind unnecessarily, slowing down loop execution.
That is unnecessary instructions in the assembler code.