Skip to main content
added syntax-highlighting
Source Link
Deduplicator
  • 9.3k
  • 5
  • 33
  • 53

In the days of K&R

  • ‘C’ was portable assembly code
  • It was used by programmers that thought in assembly code
  • The compiler did not do much optimization
  • Most computers had “complex instruction sets”, for example while ((s[i++]=t[j++]) != '\0') would map to one instruction on most CPUs (I expect the Dec VAC)

There days

  • Most people reading C code are not assembly code programmers
  • C compilers do lots of optimization, hence the simpler to read code is likely to be translated into the same machine code.

(A note on always using braces – the 1st set of code takes up more space due to having some “unneeded” {}, in my experience these often prevent code that has been badly merged from compiler and allow errors with incorrect “;” placements to be detected by tools.)

However in the old days the 2nd version of the code would have read. (If I got it right!)

concat(char* s, char *t){      
    while (*s++);
    --s;
    while (*s++=*t++);
}
concat(char* s, char *t){      
    while (*s++);
    --s;
    while (*s++=*t++);
}

In the days of K&R

  • ‘C’ was portable assembly code
  • It was used by programmers that thought in assembly code
  • The compiler did not do much optimization
  • Most computers had “complex instruction sets”, for example while ((s[i++]=t[j++]) != '\0') would map to one instruction on most CPUs (I expect the Dec VAC)

There days

  • Most people reading C code are not assembly code programmers
  • C compilers do lots of optimization, hence the simpler to read code is likely to be translated into the same machine code.

(A note on always using braces – the 1st set of code takes up more space due to having some “unneeded” {}, in my experience these often prevent code that has been badly merged from compiler and allow errors with incorrect “;” placements to be detected by tools.)

However in the old days the 2nd version of the code would have read. (If I got it right!)

concat(char* s, char *t){      
    while (*s++);
    --s;
    while (*s++=*t++);
}

In the days of K&R

  • ‘C’ was portable assembly code
  • It was used by programmers that thought in assembly code
  • The compiler did not do much optimization
  • Most computers had “complex instruction sets”, for example while ((s[i++]=t[j++]) != '\0') would map to one instruction on most CPUs (I expect the Dec VAC)

There days

  • Most people reading C code are not assembly code programmers
  • C compilers do lots of optimization, hence the simpler to read code is likely to be translated into the same machine code.

(A note on always using braces – the 1st set of code takes up more space due to having some “unneeded” {}, in my experience these often prevent code that has been badly merged from compiler and allow errors with incorrect “;” placements to be detected by tools.)

However in the old days the 2nd version of the code would have read. (If I got it right!)

concat(char* s, char *t){      
    while (*s++);
    --s;
    while (*s++=*t++);
}
added 3 characters in body
Source Link
Ian
  • 4.6k
  • 21
  • 28

In the days of K&R

  • ‘C’ was portable assembly code
  • It was used by programmers that thought in assembly code
  • The compiler did not do much optimization
  • Most computers had “complex instruction sets”, for example while ((s[i++]=t[j++]) != '\0') would map to one instruction on most CPUs (I expect the Dec VAC)

There days

  • Most people reading C code are not assembly code programmers
  • C compilers do lots of optimization, hence the simpler to read code is likely to be translated into the same machine code.

(A note on always using braces – the 1st set of code takes up more space due to having some “unneeded” {}, in my experience these often prevent code that has been badly merged from compiler and allow errors with incorrect “;” placements to be detected by tools.)

However in the old days the 2nd version of the code would have read. (If I got it right!)

concat(char* s, char *t){      
    while (s++*s++);
    --s;
    while (s++=t++*s++=*t++);
}

In the days of K&R

  • ‘C’ was portable assembly code
  • It was used by programmers that thought in assembly code
  • The compiler did not do much optimization
  • Most computers had “complex instruction sets”, for example while ((s[i++]=t[j++]) != '\0') would map to one instruction on most CPUs (I expect the Dec VAC)

There days

  • Most people reading C code are not assembly code programmers
  • C compilers do lots of optimization, hence the simpler to read code is likely to be translated into the same machine code.

(A note on always using braces – the 1st set of code takes up more space due to having some “unneeded” {}, in my experience these often prevent code that has been badly merged from compiler and allow errors with incorrect “;” placements to be detected by tools.)

However in the old days the 2nd version of the code would have read. (If I got it right!)

concat(char* s, char *t){      
    while (s++);
    --s;
    while (s++=t++);
}

In the days of K&R

  • ‘C’ was portable assembly code
  • It was used by programmers that thought in assembly code
  • The compiler did not do much optimization
  • Most computers had “complex instruction sets”, for example while ((s[i++]=t[j++]) != '\0') would map to one instruction on most CPUs (I expect the Dec VAC)

There days

  • Most people reading C code are not assembly code programmers
  • C compilers do lots of optimization, hence the simpler to read code is likely to be translated into the same machine code.

(A note on always using braces – the 1st set of code takes up more space due to having some “unneeded” {}, in my experience these often prevent code that has been badly merged from compiler and allow errors with incorrect “;” placements to be detected by tools.)

However in the old days the 2nd version of the code would have read. (If I got it right!)

concat(char* s, char *t){      
    while (*s++);
    --s;
    while (*s++=*t++);
}

In the days of K&R

  • ‘C’ was portable assembly code
  • It was used by programmers that thought in assembly code
  • The compiler did not do much optimization
  • Most computers had “complex instruction sets”, for example while ((s[i++]=t[j++]) != '\0') would map to one instruction on most CPUs (I expect the Dec VAC)

There days

  • Most people reading C code are not assembly code programmers
  • C compilers do lots of optimization, hence the simpler to read code is likely to be translated into the same machine code.

(A note on always using braces – the 1st set of code takes up more space due to having some “unneeded” {}, in my experience these often prevent code that has been badly merged from compiler and allow errors with incorrect “;” placements to be detected by tools.)

However in the old days the 2nd version of the code would have read. (If I got it right!)

concat(char* s, char *t){      
    while (!s++);
    --s;
    while (!(s++=t++));
}

In the days of K&R

  • ‘C’ was portable assembly code
  • It was used by programmers that thought in assembly code
  • The compiler did not do much optimization
  • Most computers had “complex instruction sets”, for example while ((s[i++]=t[j++]) != '\0') would map to one instruction on most CPUs (I expect the Dec VAC)

There days

  • Most people reading C code are not assembly code programmers
  • C compilers do lots of optimization, hence the simpler to read code is likely to be translated into the same machine code.

(A note on always using braces – the 1st set of code takes up more space due to having some “unneeded” {}, in my experience these often prevent code that has been badly merged from compiler and allow errors with incorrect “;” placements to be detected by tools.)

However in the old days the 2nd version of the code would have read. (If I got it right!)

concat(char* s, char *t){      
    while (!s++);
    while (!(s++=t++));
}

In the days of K&R

  • ‘C’ was portable assembly code
  • It was used by programmers that thought in assembly code
  • The compiler did not do much optimization
  • Most computers had “complex instruction sets”, for example while ((s[i++]=t[j++]) != '\0') would map to one instruction on most CPUs (I expect the Dec VAC)

There days

  • Most people reading C code are not assembly code programmers
  • C compilers do lots of optimization, hence the simpler to read code is likely to be translated into the same machine code.

(A note on always using braces – the 1st set of code takes up more space due to having some “unneeded” {}, in my experience these often prevent code that has been badly merged from compiler and allow errors with incorrect “;” placements to be detected by tools.)

However in the old days the 2nd version of the code would have read. (If I got it right!)

concat(char* s, char *t){      
    while (s++);
    --s;
    while (s++=t++);
}
Source Link
Ian
  • 4.6k
  • 21
  • 28
Loading