Skip to main content
Commonmark migration
Source Link

###Assign instead of return.

Assign instead of return.

This is not really standard C, but works with every compiler and CPU that I know of:

int sqr(int a){return a*a;}

has the same effect as:

int sqr(int a){a*=a;}

Because the first argument is stored into the same CPU register as the return value.

Note: As noted in one comment, this is undefined behaviour and not guaranteed to work for every operation. And any compiler optimization will just skip over it.

X-Macros

###X-Macros AnotherAnother useful feature: X-Macros can help you when you have a list of variables and you need to do some operation which involve all of them:

https://en.wikipedia.org/wiki/X_Macro

###Assign instead of return.

This is not really standard C, but works with every compiler and CPU that I know of:

int sqr(int a){return a*a;}

has the same effect as:

int sqr(int a){a*=a;}

Because the first argument is stored into the same CPU register as the return value.

Note: As noted in one comment, this is undefined behaviour and not guaranteed to work for every operation. And any compiler optimization will just skip over it.

###X-Macros Another useful feature: X-Macros can help you when you have a list of variables and you need to do some operation which involve all of them:

https://en.wikipedia.org/wiki/X_Macro

Assign instead of return.

This is not really standard C, but works with every compiler and CPU that I know of:

int sqr(int a){return a*a;}

has the same effect as:

int sqr(int a){a*=a;}

Because the first argument is stored into the same CPU register as the return value.

Note: As noted in one comment, this is undefined behaviour and not guaranteed to work for every operation. And any compiler optimization will just skip over it.

X-Macros

Another useful feature: X-Macros can help you when you have a list of variables and you need to do some operation which involve all of them:

https://en.wikipedia.org/wiki/X_Macro

added 166 characters in body
Source Link
G B
  • 22.8k
  • 1
  • 20
  • 53

###Assign instead of return.

This is not really standard C, but works with every compiler and CPU that I know of:

int sqr(int a){return a*a;}

has the same effect as:

int sqr(int a){a*=a;}

Because the first argument is stored into the same CPU register as the return value.

Note: As noted in one comment, this is undefined behaviour and not guaranteed to work for every operation. And any compiler optimization will just skip over it.

###X-Macros Another useful feature: X-Macros can help you when you have a list of variables and you need to do some operation which involve all of them:

https://en.wikipedia.org/wiki/X_Macro

###Assign instead of return.

This is not really standard C, but works with every compiler and CPU that I know of:

int sqr(int a){return a*a;}

has the same effect as:

int sqr(int a){a*=a;}

Because the first argument is stored into the same CPU register as the return value.

###X-Macros Another useful feature: X-Macros can help you when you have a list of variables and you need to do some operation which involve all of them:

https://en.wikipedia.org/wiki/X_Macro

###Assign instead of return.

This is not really standard C, but works with every compiler and CPU that I know of:

int sqr(int a){return a*a;}

has the same effect as:

int sqr(int a){a*=a;}

Because the first argument is stored into the same CPU register as the return value.

Note: As noted in one comment, this is undefined behaviour and not guaranteed to work for every operation. And any compiler optimization will just skip over it.

###X-Macros Another useful feature: X-Macros can help you when you have a list of variables and you need to do some operation which involve all of them:

https://en.wikipedia.org/wiki/X_Macro

Source Link
G B
  • 22.8k
  • 1
  • 20
  • 53

###Assign instead of return.

This is not really standard C, but works with every compiler and CPU that I know of:

int sqr(int a){return a*a;}

has the same effect as:

int sqr(int a){a*=a;}

Because the first argument is stored into the same CPU register as the return value.

###X-Macros Another useful feature: X-Macros can help you when you have a list of variables and you need to do some operation which involve all of them:

https://en.wikipedia.org/wiki/X_Macro