- 1
- 2
- 3
- 4
- 5
- 6
- 7
/* */
int fooBar() {
/* do something */
/* - */ return NULL;
/* + */ return 0ULL;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+145
/* */
int fooBar() {
/* do something */
/* - */ return NULL;
/* + */ return 0ULL;
}
> src/foobar.c:42:3: warning: return makes integer from pointer without a cast
> return NULL;
П О Ч И Н Е Н О
Из C99: NULL which expands to an implementation-defined null pointer constant;
Ну и в гнутой либе точно так же (плагиаторы!): > implementation-defined
Так я и знал...
#define NULL ((void *) 0)
An integer constant expression is something that evaluates at compile time and is of an integer type. Integer types are all the standard integer types that we all know, including plain char and _Bool, and enumeration types. In particular such expressions may contain casts to such types.
So far this all sounds relatively innocent if you think of the primary use of null pointer constants namely to be assigned to pointer variables, but see below.
This means that NULL may result in at least 12 different standard integer types and many more expressions that result in a null value in that type:
[...]
In summary,
* NULL obfuscates an expression that can be either of integer type or of pointer type.
* Whenever you want to initialize or assign to a pointer to a null value, use plain 0, it does serve well.
* Whenever you use a null value in a function call for a parameter that has no prototype use (T*)0.
https://gustedt.wordpress.com/2010/11/07/dont-use-null/
Отака хуйня, малята.
Вот я понимаю, C++, шаблоны, NULL и std::nullptr_t.
char * ptr = '\0';
http://ideone.com/rm7sr6
the result is implementation-defined, might not be correctly aligned, might not point to an
entity of the referenced type, and might be a trap representation.