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

C/C++ tricks

Name: Anonymous 2016-10-20 4:14

Did you know, that keeping frequently accessed field at the start of a struct/class can greatly boost access time and decrease code size? I got like 1/10 speed up.

Name: Anonymous 2016-10-20 4:40

>>1 Adressof first field==address of struct

Name: Anonymous 2016-10-20 5:15

thanks

Name: Anonymous 2016-10-20 11:05

>>1
Doesn't the Standard allow the compiler to rearrange struct members, making this technique unreliable?

Name: Anonymous 2016-10-20 11:34

>>4 http://stackoverflow.com/questions/9115020/order-of-fields-in-c-c-structs
Remember everything in C is just pointers with syntax sugar.

Name: Anonymous 2016-10-20 13:42

>>4

Never seen any compiler doing that in practice.

Name: Anonymous 2016-10-20 13:44

>>6

And almost every C program depends on fields being ordered as specified by programmer.

Name: Anonymous 2016-10-20 15:20

>>4
nah the struct fields do stay in order. please check the spec. before making comments /prog/ is known for maintaining a high standard of discussion.

Name: Anonymous 2016-10-20 16:28

>>7
Not true

Name: Anonymous 2016-10-20 16:37

>>9

void get_foo(void *filename) {
return ((header_t*)get_file_bytes(filename))->foo;
}

Name: Anonymous 2016-10-20 17:13

Anyone have a collection of C tricks?

Name: Anonymous 2016-10-20 17:28

>>10
A struct cannot have a member of type void.

Name: Anonymous 2016-10-20 17:31

>>12
#define void int

Name: Anonymous 2016-10-20 17:46

>>12 it can have pointers to void(void*)

Name: Anonymous 2016-10-20 19:00

>>14
yeah but then the function signature would be
void *get_foo(void *), not
void get_foo(void *)

Name: Anonymous 2016-10-20 20:22

>>11
Anyone have a collection of C tricks?
Yes. I have. In my memory. A lot of stuff like http://perltricks.com/article/the-history-of-the-schwartzian-transform/

Name: Anonymous 2016-10-20 20:29

http://codepad.org/ZbcUt1xp (C type safety)

Name: Anonymous 2016-10-20 21:48

>>17
That's not valid C. main() must have a return type of int, and using a void function where a value is expected isn't allowed.

The following code will compile, but the return value of main() is undefined:

void abc(){return 2;}
int(*func)() = abc;
int main(){return func();}

Name: Anonymous 2016-10-20 23:14

>>10
No sane person does this.

Name: Anonymous 2016-10-20 23:20

Name: Anonymous 2016-10-20 23:51

>>19

I do and I'm sane.

Name: Anonymous 2016-10-21 0:49

>>21
No you aren't.

Name: Anonymous 2016-10-21 0:57

>>18
http://stackoverflow.com/questions/204476/what-should-main-return-in-c-and-c
I'm guessing here (I don't actually know if this is a fact) but modern C compilers will generate the proper main() function signature if it was declared as void main(). I remember seeing this somewhere but I can't remember where.

Name: Anonymous 2016-10-21 1:07

>>23
GCC rejects void main().

Name: Anonymous 2016-10-21 1:46

#import <stdio.h>
int main()
{
printf("Hello world\n");
return 0;
}

Name: Anonymous 2016-10-21 2:58

>>25
#import
incomplete function signature
indenting with two spaces
Terrible!

Name: Anonymous 2016-10-21 7:05

>>13
#include <void.h>

Name: Anonymous 2016-10-21 9:02

>>26
Whom are thou quoting?

Name: Anonymous 2016-10-21 15:01

#define import #include

Name: Anonymous 2016-10-21 15:05

>>28
s/e/t/

Name: Anonymous 2016-10-21 15:37

TIL that #import is a valid GCC preprocessing directive which guarantees that the header file in question will be included at most once per translation unit, even if the header file lacks include guards or a #pragma once directive.

Name: Anonymous 2016-10-21 22:52

>>31
GCC

not even once

Name: Anonymous 2016-10-21 22:52

>>32

clang

Name: Anonymous 2016-10-21 23:55

>>33
who are you quoting?

Name: Anonymous 2016-10-22 5:50

>>31 #pragma once is portable across many compilers, #import isn't

Name: Anonymous 2016-10-22 5:52

>>35
That's why I specified GCC.

Name: Anonymous 2016-10-22 8:37

c is a codeword for anti white

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