The present invent
The present invent
// SuperTux // C
As part of a pilot
In recent years, t
Brasil: Ao menos c
AUSTIN - After two
It may be just wee
This invention rel
New Mexico Gov. Su

Introduction {#Sec
I’ve been using Wo
Show HN: A JavaSc
Q: Can I have an
Therapeutic drug m
[Study of the mech
"He was the one wh
Vision from the he
Cochlear developme
Q: Avoiding SQL I
#ifndef __STDLIB_H #define __STDLIB_H #include #include #include #define malloc(size) ((size) ? malloc(size) : 0) #define realloc(ptr, size) ((size) ? realloc((ptr), (size)) : 0) #define free(ptr) ((ptr) ? free((ptr)) : 0) #define calloc(count, size) ((size) ? calloc((count), (size)) : 0) /* this prevents unused parameters warning with gcc */ #define UNUSED(x) (void)(x) #define PRId64 "ll" static inline int getpagesize(void) { int pageSize = 0; pageSize = sysconf(_SC_PAGESIZE); if (pageSize < 0) { errno = EINVAL; } return pageSize; } #endif /* __STDLIB_H */ Is there anything I can add in my code to reduce the number of warnings? I am using -Wall -Werror -Wextra (gcc 4.6) A: This line is incorrect: #define PRId64 "ll" It should be: #define PRId64 "lld" You want to set the PRId64 preprocessor variable to contain a "long long" as defined in the ISO C standard for the sizeof operator. This will enable you to write sizeof(int) == sizeof(long) * 8 and sizeof(char) == sizeof(int) * 8 without compiler warnings. (For more on using the ISO C standard types, see the book "Advanced C" by Herbert Schildt.) The default (on GNU/Linux) is to use either a "long" or a "long long" as a "natural size" for types like int and long. You can set the GCC compiler flag "-std=gnu99" to enable GNU extensions which define the "natural size" for types to be a "long long". This will allow you to use sizeof(char) == sizeof(int) * 8 without compiler warnings, but it will also allow sizeof(long) == 2 and sizeof(long long) == 8. See also section 2.4.3 here. Note that this is a non-standard GCC extension, not in ISO C99, and is often enabled automatically by using -std=gnu99 (or -std=c99 with GNU). The ISO C99 standard, as defined in "The Open Group Base Specifications Issue 6" defines the natural size for types int and long to be the minimum of the pointer size and the word size (also known as the "machine word size"). On 32-bit architectures this is often 32 bits (which is what you get when using -m32 to compile), but on 64-bit architectures this is often 64 bits (which is what you get when not using -m32). If you use -m64, GCC will define the natural size for a "long" (which is the same as the natural size for "int" in this case) as 64 bits. Thus you should use GCC built-in types rather than POSIX types if you want ISO C99-compatibility. (And use POSIX types if you want to have ISO C99 compatibility with a POSIX-compatible compiler on a system where the word size is different from the natural size for your OS, such as Solaris.) For the above code to work correctly, you need to use the GNU-specific types like ssize_t and memsize_t for types like size_t and ssize_t. (It might work with "long long" (i.e. a 64-bit type) for ssize_t on 64-bit OSes, but I wouldn't bet on it.) A: The best way is to get rid of the warning is to change your warning options: -Wall -Wformat -Wconversion -Wvla-extension -Wwrite-strings These are your compilation flags, you can specify them on the command line when invoking gcc. A: You can use -Wall -Werror with -std=c99 if you want to fix gcc warnings. -Wall tells gcc to include most warnings while -Werror makes gcc abort with a diagnostic in case of error. The error message you get (when you use unsigned long long): sizeof.c:20:6: warning: overflow in implicit constant conversion [-Woverflow] size_t len = sizeof (str); ^ sizeof.c:20:6: error: too many arguments to function ‘size_t sizeof(char*)’ sizeof.c:20:6: warning: excess elements in scalar initializer sizeof.c:20:6: error: too many arguments to function ‘size_t sizeof(char*)’ Is an implementation-defined behaviour of the sizeof operator which returns a value of type size_t but the value may not fit in an integer. This warning and error message is provided by the ISO C standard, see 6.5.3.4p3 (size_t). The code for sizes_t as described in the C99 standard is (emphasis mine): For any two-expression function call, the type and value of the result depend on the type and value of the function’s arguments. If the function is defined with a type that includes a prototype, and either the prototype ends with a return type that is not a valid type for the corresponding expression or the function is defined with a type that does not include a prototype, the behavior is undefined. The ISO C standard says nothing about the return type for a function of type size_t. Therefore, GCC behaves like its implementation defines it in a way you don't like. You can fix that by specifying type int for your compiler (or int128_t) or by using an implicit conversion which isn't too surprising since you want to work on bytes. Unfortunately, this is not supported in C99, see http://gcc.gnu.org/onlinedocs/gcc-4.6.2/gcc/Function-Attributes.html#Function-Attributes, but could be added to a future version of the standard.