The only 'valid' wrapper for malloc that I can think of is:
void *alloc(size_t size)
{
void* mem;
mem = malloc(size);
if (!mem) {
fprintf(stderr, "Out of memory!\n");
Type: Posts; User: notan
The only 'valid' wrapper for malloc that I can think of is:
void *alloc(size_t size)
{
void* mem;
mem = malloc(size);
if (!mem) {
fprintf(stderr, "Out of memory!\n");
No there is no difference in this case, as correctly stated in the FAQ:
Rule 3:
An array name in the declaration of a function parameter is
treated by the compiler as a pointer to the first...
Closing an invalid file descriptor is not a bad thing, closing an again valid descriptor is where things go really bad. When you searched this kind of bug in VxWorks where filedescriptors are shared...
C treats the following definitions the same (sad but true).
int foo(int bar[10]);
int foo(int bar[]);
int foo(int *bar);
therefore sizeof bar is always the size of a single pointer (4 on...
Well the 'obscure' thing is that C accepts
int foo(short bar[8])
even as the number is redundant and unused. As the compiler does not care about the size of the array it shall insist on...
Nothing is the best case.
Launching nukes is the worst case, but unfortunately not impossible.
Be aware of closed handles and dangling pointers, they might send you straight to hell.
will loop infinitely when 0 is entered, use >1 instead of !=1.
You want to assign count the incremented value, thus ++ is on the wrong side.
Ampersand missing at parameter for scanf.
Will not work...
Closing the fd twice is dangerous and bad practice, as closed file descriptors will be recycled later, therefore your second close may close a file opened by someone else in the meantime.
I...
The right way to program it is
float a = 0.7f;
if (a > 0.7f) {
/* you will not reach this hell */
} else {
/* this is the place we go */
}
Is there a good standard alternative to the
sizeof(array)/sizeof(array[0])
used for determining the size of an array?
Well sometimes you see:
sizeof array/sizeof*array