- 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;
П О Ч И Н Е Н О
codemonkey 11.03.2015 17:45 # 0
Dummy00001 11.03.2015 17:47 # 0
Xom94ok 11.03.2015 18:09 # +3
Dummy00001 11.03.2015 18:15 # +1
bormand 11.03.2015 20:19 # +2
kegdan 11.03.2015 21:24 # 0
absolut 12.03.2015 08:16 # 0
Из C99: NULL which expands to an implementation-defined null pointer constant;
bormand 12.03.2015 08:51 # 0
Ну и в гнутой либе точно так же (плагиаторы!): > implementation-defined
Так я и знал...
codemonkey 11.03.2015 18:24 # 0
#define NULL ((void *) 0)
3.14159265 11.03.2015 20:13 # 0
3.14159265 11.03.2015 21:33 # +1
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/
Отака хуйня, малята.
1024-- 11.03.2015 21:52 # 0
Вот я понимаю, C++, шаблоны, NULL и std::nullptr_t.
Xom94ok 11.03.2015 21:54 # +1
char * ptr = '\0';
http://ideone.com/rm7sr6
absolut 12.03.2015 07:56 # 0
someone 12.03.2015 08:28 # +1
absolut 12.03.2015 08:44 # 0
bormand 12.03.2015 08:52 # +3
absolut 12.03.2015 09:20 # +2
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.