Jump to content

Useless instructions: Difference between revisions

Added C
(Added C)
Line 23:
=={{header|8086 Assembly}}==
<code>xor ax,ax</code> (or any other data register) takes fewer bytes to encode than <code>mov ax,0</code> and achieves the same result. The only difference is that <code>mov ax,0</code> doesn't set the flags, which can be used to the programmer's advantage when sequencing operations.
 
=={{header|C}}==
C can boast (if that's the right word) analogous redundant constructions to the Go and Wren examples though you might get warnings with some compilers. AFAIK creating an empty struct is also useless and may produce a warning or even an error as it's technically non-standard.
 
However, C has a more obvious form of redundancy in the shape of the 'auto' keyword. This was inherited from the 'B' language where it was needed to declare a local variable though is never needed in C itself.
 
Another keyword which is teetering on redundancy is 'register' whose purpose is to suggest to the compiler that it should store a variable in a CPU register rather than memory. However, modern optimizing compilers don't need such a suggestion and will use CPU registers anyway if they deem it appropriate. But it may still be relevant in embedded system programming so it can't be said to be completely redundant at the present time.
 
<lang c>#include <stdio.h>
#include <stdbool.h>
 
void uselessFunc(int uselessParam) { // parameter required but never used
auto int i; // auto redundant
 
if (true) {
// do something
} else {
printf("Never called\n");
}
 
for (i = 0; i < 0; ++i) {
printf("Never called\n");
}
 
while (false) {
printf("Never called\n");
}
 
printf(""); // no visible effect but gcc 9.3.0 warns against it
 
return; // redundant as function would return 'naturally' anyway
}
 
struct UselessStruct {
// no fields so effectively useless and apparently non-standard in any case
};
 
int main() {
uselessFunc(0);
printf("Working OK.\n");
}</lang>
 
{{out}}
<pre>
Working OK.
</pre>
 
=={{header|Go}}==
9,482

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.