'C makes it easy to shoot yourself in the foot. C++ makes it harder, but when you do, it blows away your whole leg.' -Bjarne Stroustrup
Reference : http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf
ed2k://|file|n1256.pdf|3788603|a728a3c5e98e681a8c389ffc46640625|
On X86 architechure (running Linux or Windows ) :
# sizeof(char)=1 # sizeof(void)=1 @ gcc@[[Linux]] & 0 @ [[MSVC]]@[[Windows]]
# sizeof(short)=2
# sizeof(int)=4 # sizeof(void*)=4 # sizeof(char*)=4 # sizeof(long int)=4 # sizeof(long)=4
# sizeof(double)=8 # sizeof(long long)=8 // long long is not ansi and not supported by msvc
struct buffer { unsigned int size_; char* pbytes_; }
enum colors { RED=1, YELLOW, GREEN=6, BLUE };
Now RED=1, YELLOW=2, GREEN=6 and BLUE=7.
The main advantage of enum is that if you don't initialize your constants, each one would have a unique value. The first would be zero and the rest would then count upwards.
T limitmax = ((tmp=~0)==(tmp>>1)?~(tmp<<((sizeof(tmp)<<3)-1)):tmp);
int w[[]] = {1,2,3};
Java supports both :
int[[]] v = {1,2,3}; int w[[]] = {1,2,3};
//static allocation (on compile time) static char img[[h]][[w]][[IMAGE_DEPTH]]; img[[h]][[w]][[k]] = 'a'; unsigned char* ptr = &img[[0]][[0]][[0]];
// dynamic allocation (on run pimg = new char[[h*w*IMAGE_DEPTH]]; time) pimg[[(ih*w*IMAGE_DEPTH)+(iw*IMAGE_DEPTH)+k]] = 'a' ;
// both are stored the same in RAM memcmp( ( char*) pimg, ( char*) ptr, h*w*IMAGE_DEPTH) ); // =0 //same
See how array can be usefull
int f(int c[[]][[2]] ) { c[[0]][[0]] = 1; }
int main(int argc, char* argv[[]]) { int a[[1]][[2]]; a[[0]][[0]] = 0; f(a); debugi( a[[0]][[0]] ); //1 }
Bit MASK :
int reverseColor_ARGB_to_BGRA(int c) { int b= c &0xFF; int g = (c>>8) &0xFF; int r = (c>>16) &0xFF; int a = (c>>24) &0xFF;
// return ( a | (r<<8) | (g<<16) | (b<<24) ); // may be unsafe
return ( a | ( (r<<8) &0xFF00 ) | ( (g<<16) &0xFF0000 ) | ( (b<<24) &0xFF000000 ) );
}
<RzR> can you tell why in std libs they use : “const char *” while “char const * const” …could be used
<The_Vulture> RzR: because the other const just makes the pointer itself const, and since it's passed by value, that wouldn't make a difference to the caller
<The_Vulture> an implementation could add or remove the extra const without making any difference to the caller
<RzR> your answser is smart
return-type function-name(paramater-type-list); int (*aaron(char *(*)(void)) (long, int);
Defines the function aaron which returns a pointer to a function.
The function aaron takes one argument: a pointer to a function
which returns a character pointer and takes no arguments.
The returned function returns a type int
and has two parameters of type long and int.
typedef struct my_stack_s my_class_t;
struct my_stack_s { /* method "push" with one parameter and no return value */ void (*push)(my_stack_t *this, int i);
/* method "add" with no parameters and no return value */ void (*add)(my_stack_t *this);
/* method "pop" with no parameters (except "this") and a return value */ int (*pop) (my_stack_t *this); };
/* constructor */ my_class_t *new_my_stack(void);
cat > main.c << EOF && make main && ./main p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);} EOF
i++ vs ++i ?
++i does not create a temp object and addition, so it is better and faster
CPU : simd : http://ds9a.nl/gcc-simd/ http://gcc.gnu.org/onlinedocs/gcc-3.4.0/gcc/X86-Built-in-Functions.html
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_0zn6.asp have fun of bmiColors1;
<mornifle> le mieux etant de lire le header xmmintrin.h