Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Passing small structs in C

Name: Anonymous 2013-07-28 13:51

Hi prog. Got a C89 problem.

I want to pass small (less than 64B) structs throught functions that I can't inline because they are used several times elsewhere and are quite big. But it still need it to be very fast.

Should I pass the structs directly (thus copying them) or use a pointer (and getting a dereference penalty) ?

Name: Anonymous 2013-07-28 19:15

>>4,5

Just tried it out, even in 32-bit 86, Clang will break a struct up and pass it in registers if the function isn't public. You can view the source and assembly output here:

http://gcc.godbolt.org/#{%22version%22%3A3%2C%22filterAsm%22%3A{%22labels%22%3Atrue%2C%22directives%22%3Atrue%2C%22commentOnly%22%3Atrue}%2C%22compilers%22%3A[{%22source%22%3A%22%23include%20%3Cstdio.h%3E\n\nstruct%20suss_t\n{\n%20%20%20%20char*%20text%3B\n%20%20%20%20int%20number%3B\n}%3B\n\nvoid%20xarnicate%28suss_t%20s%29%20{\n%20%20%20%20printf%28\%22String%3A%20%25s%2C%20Number%3A%20%25i\%22%2C%20s.text%2C%20s.number%29%3B\n}%22%2C%22compiler%22%3A%22%2Fusr%2Fbin%2Fclang%2B%2B%22%2C%22options%22%3A%22-O2%20-march%3Dnative%22}]}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List