- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
#include <stdio.h>;
void check(int x, int y) {
if (2*x == y && y < 0 && 0 <= 2*x) {
puts("Impossible!");
}
}
int main() {
check(0x7F80007F, 0xFF0000FE);
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
Всего: 332
0
#include <stdio.h>;
void check(int x, int y) {
if (2*x == y && y < 0 && 0 <= 2*x) {
puts("Impossible!");
}
}
int main() {
check(0x7F80007F, 0xFF0000FE);
}
https://runtimeverification.com/blog/?p=257
When writing code for a specific compiler you can rely on the implementation-specified behavior, but signed overflow is still problematic. GCC promises that conversions between integer types will be reduced modulo the appropriate power of two when the value is not representable in the target type. This means that with GCC the conversion above will initialize var to -0x112234 on any architecture that GCC supports. However, only initialization and other conversions are safe. GCC still considers signed overflow in arithmetic as undefined behavior, and optimizes under the assumption that there will be no overflow. This can lead to apparently impossible results when signed values do overflow. Compiled with -O3, this program prints “Impossible!”.
By adding apparently-redundant casts to 2*x to give (int)(2*(unsigned int)x), the calculation becomes implementation-specified behavior from an out-of-range conversion instead of undefined behavior. While this code may not be portable between compilers, GCC now guarantees the “impossible” code will not be executed even with -O3.
+1
var x = '$$>1 ? eval(x.replace(/\\$\\$/g, $$-1)) + eval(x.replace(/\\$\\$/g, $$-2)) : 1';
eval(x.replace(/\$\$/g, 5))
Yo dawg, I heard you like evaluation. So I put evaluation in your evaluation so you could evaluate while you evaluate
Фибоначчи, по мотивам http://govnokod.ru/20105#comment330201 хуйни
+2
for(i==1;i<=1000;i++)
https://youtu.be/Tzl0ELY_TiM?t=89
И эти люди хотят кого-то учить программированию?
+2
for(uint64_t i = 0ULL; i <= 999999999ULL; i+= 1)
{
long double a = 0.00005l * i; // это чтоб в плавучке не накапливались ошибки.
somefunction(a);
....
}
0
https://web.archive.org/web/20070125181458/http://2ch.ru/s/src/1158095011998.gif
0
#define SPLICE(a,b) SPLICE_1(a,b)
#define SPLICE_1(a,b) SPLICE_2(a,b)
#define SPLICE_2(a,b) a##b
#define LL(a,b) SPLICE_2(a,b)
#define L(a) LL(a,LOC)
#define LOC sub1
.func sub1
sub1:
ljmp L(L1)
L(L1):
nop
.endfunc
#define LOC sub2
.func sub2
sub2:
ljmp L(L1)
L(L1):
nop
.endfunc
Когда захотел сделать local labels в ассемблере через сишный препроцессор
−33
#include <http://govnokod.ru/21585>
// assembly output for f1_signed and f2_signed on GCC 7,6,5 ... versions are same
signed char f1_signed(signed char a1, signed char a2, signed char a3)
{
return MAXS(a1,a2,a3,a1,a2,a3);
}
signed char f2_signed(signed char a1, signed char a2, signed char a3)
{
return MAXS(a1,a2,a3);
}
// assembly output for f1_unsigned and f2_unsigned on GCC 7,6,5 ... versions are differend
// GCC compiler can't do same simplification for unsigned function
// This function produces much more assembler code than second
unsigned char f1_unsigned(unsigned char a1, unsigned char a2, unsigned char a3)
{
return MAXS(a1,a2,a3,a1,a2,a3);
}
unsigned char f2_unsigned(unsigned char a1, unsigned char a2, unsigned char a3)
{
return MAXS(a1,a2,a3);
}
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80574
Очередной мой багрепорт в GCC. Компилятор GCC может заоптимизировать повторяющуйся в MAXS хрень для signed char, но не может для unsigned
А вот Clang не может заоптимизировать ни то, ни другое. https://godbolt.org/g/7Kt9X0
−11
void *memcpy(void *__dest, __const void *__src, size_t __n)
{
int i = 0;
unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src;
for (i = __n >> 3; i > 0; i--) {
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
}
if (__n & 1 << 2) {
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
}
if (__n & 1 << 1) {
*d++ = *s++;
*d++ = *s++;
}
if (__n & 1)
*d++ = *s++;
return __dest;
}
Царский анролл в memcpy, прямиком из ядра Linux
http://lxr.free-electrons.com/source/arch/arm/boot/compressed/string.c
−11
https://habrahabr.ru/post/322052/
Лямбда-исчисление на JavaScript
−16
https://foxford.ru/wiki/informatika/tipy-tselyh-chisel-yazyka-s
Вот такая хуйня получается, когда учебные материалы по Си пишут те, которые сами нихуя не знают Си и не читали Священный Драфт Стандарта. Сколько хуйни по ссылке вы можете найти?
spoiler: https://habrahabr.ru/post/156593/