Is an empty statement in C, Java, ... no-op programming languages ​​in Assembler?

A few days ago, I saw that for ( ; ; ) leads to an infinite loop. It made me think of two things.

  • Is the empty statement (;) no-op in assembler
  • Why is it rated as β€œtrue” in the above example?
+4
source share
1 answer

Answering in terms of C here:

No ; not translated into no-op instructions. No-op instructions (e.g. nop ) are explicit assembly-level instructions that usually do something (in that they consume time, although they do not necessarily affect any stored state in the CPU).

The for(;;) snippet is a for loop with default values ​​for each of the three sections. You can come up with ; in this case, it is not an empty operator, but a separator for partitions (a) .

  • The first section (initialization) has a default value of "do nothing".
  • The second section is the condition under which the cycle will continue. Its default value is forever.
  • The third section, the steps you need to take before starting the next iteration, also "does nothing."

In the past, I was guilty of a heinous crime of using things such as:

 #define ever ;; #define forever for (;;) 

so that I can write my infinite loops like:

 for(ever) { ... } forever { ... } 

I would not do this at the moment, of course.


(a) A "true" empty line operator:

 if (condition) { a = b; ; } 

also probably not translate to no-op. Most likely, this will not lead to the whole code.

Remember that this is based on fairly common behavior. From the point of view of C ; can generate any lower-level code that it wants, until it affects the "virtual machine", which is environment C. For example, if you have profiling, you can increase, for example, the number of hidden line numbers and update coverage statistics.

+6
source

Source: https://habr.com/ru/post/1369619/


All Articles