- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
#include <stdio.h>
struct{int a; float b;} test()
{
return (typeof(test())){1337, 666.666};
}
int main()
{
auto a = test();
printf("%d %f\n", a.a, a.b);
return 0;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
#include <stdio.h>
struct{int a; float b;} test()
{
return (typeof(test())){1337, 666.666};
}
int main()
{
auto a = test();
printf("%d %f\n", a.a, a.b);
return 0;
}
В стандарт C23 добавили auto и теперь можно писать такую хуйню. В "Clang" работает: https://godbolt.org/z/GG3addqPb
0
#include <stdio.h>
int bts(unsigned int n, int bitN) {
return n & (1 << bitN);
}
int main() {
volatile char *p_lacoon;
unsigned char res = 0;
p_lacoon = ((unsigned )p_lacoon | 01 << 1);
res |= bts(p_lacoon, 0) | bts(p_lacoon, 1);
p_lacoon = ((unsigned )p_lacoon | 01 & ~!~0);
p_lacoon = ((unsigned )p_lacoon | 01 << 1 << 0);
res |= 4 << (bts(p_lacoon, 0) | bts(p_lacoon, 1) ^ 3);
p_lacoon = ((int)p_lacoon | 01 & ~0xFE | 00);
p_lacoon = ((int)p_lacoon | 01 << 1);
res |= ~!0xFF << (bts(p_lacoon, 0) | 6 ^ 0x29b);
res |= ~!0xFC << (bts(p_lacoon, 1) | 4 ^ 0x29c);
res |= ~!0xF0 << 5;
p_lacoon = (int)p_lacoon >> 01 >> 001 << 001 << 01;
printf("%x, %X %s\n", p_lacoon, (res & 001) ? res-1 : res, "*****. Challenge everything.");
}
Предтерминальная стадия мозгфускации.
Из собеса в подразделение AMD: продемонстрировать варианты хранения при недостатке памяти.
Работает в GCC, ICC, Clang только -O0.
Кто хочет разобраться - welcome https://godbolt.org/z/hd4eYeM1Y
0
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <limits.h>
int gcc_rtm_virt_test(int a, int(*f)(int, int(*)(), float*), float fa[static (-1,0,1)]) {
short s = sizeof (short) + sizeof 0;
char b[12] = "0123456789";
for (long ll = sizeof b; ll -= 4;) {
b[ll] = '0';
b[ll-1] = '1';
b[ll-2] = '2';
b[ll-3] = '3';
}
return s - ((1 << 2) - (b[0] - '2'));
}
int gcc_rtm_cf32(int(*f0)(), int(*f1)()) {
ptrdiff_t d = f1 - f0;
// guess you know what you're doing
if (! (d >> sizeof (ptrdiff_t) * CHAR_BIT - 1)) {
while (d--) {
switch(*(unsigned short*)(f0 + d)) {
case 0xc3c9:
return 0;
case 0xb8:
if (!*(unsigned int*)(f0 + d + 1)) {
return 1;
}
break;
case 0xC031:
return 2;
}
}
return -1;
};
return -2;
}
int main() {
switch (gcc_rtm_cf32(gcc_rtm_virt_test, gcc_rtm_cf32)) {
case -1:
fprintf(stderr, "Hey, added smth. special? Maybe -Og? \n"), abort();
break;
case 0:
fprintf(stderr, "Hey, -O0 smells like a dead rat.. check your flags!\n"), abort();
break;
case 1:
fprintf(stderr, "Hey, -O1 is still not allowed.. Would you do better?\n"), abort();
break;
case 2:
fprintf(stdout, "Hey, finally you've captured [-O2 || -O3 || -Ofast || -Os] flag!");
break;
default:
fprintf(stderr, "Hey, looks like you've got impl. defined crap, check PTRDIFF_T stuff.. \n"), abort();
break;
};
}
И далее по тексту..gcc'шники опять обкурились в рантайме. Зачэм так делоть, это прикольно?
0
void rtm_guard(void) {
/*
Don't even try to MS VC that stuff, zerobuffy 4eyes.
*/
unsigned char buf0[0];
unsigned a = 0xF001BA11;
unsigned b = 0xF001BA11;
unsigned c = 0x55550000;
unsigned d = 0xF001BA11;
unsigned e = 0xF001BA11;
unsigned char buf1[0];
ptrdiff_t diff = buf0 - buf1;
const char* prnt;
switch (diff) {
case sizeof rtm_guard:
prnt = "dear Nizhny Novgorod '-O1' lover";
break;
case sizeof (int):
prnt = "'gcc -O0' bastard";
break;
default:
prnt = "\b";
};
(diff == sizeof (int) || diff == sizeof rtm_guard) ?
fprintf(stderr, "%s%s%s",
"Hey you, ", prnt, ", what the hell are you trying to bang here w/o mandatory flags? Forgot something? \n"), abort() :
0;
}
Сodebomb в рантайме наложил. Но нафига? Присосаться хуком и послать курить джуника с лидом как рукопожато билдить?
0
#include <console_io.h>
конио
0
// https://tio.run/##jY9PC4JAFMTv@ymGJHFjDc06WUEdugpd1YPomgu2in8oED@7WVpRh@jdZt7vDfNCPUwDeeo6oggZpnXEsS6rSGTzZEuIEvFYSI6D42g5QxbHJa8oogwNPIJ@8kLIKtYm06snJwxq7uoD5VO7R1pcEpFyzaDvsP3u@F/YjyzSgzgHQmoUzeP2bgSujw0ag8FkWDBYDEuGVWu/iFneA2rgWv7gjY@Z9FPWox6rml/yuS54VRcShk3arrsB
#include <stdio.h>
#define FOO(p, offset) do { \
printf("%x\n", &p[-offset]); \
} while(0)
#define BAR(p, offset) do { \
printf("%x\n", p[-offset]); \
} while(0)
int main() {
int a[] = {0, 1, 2, 3, 4, 5};
int *p = &a[3];
FOO(p, 1);
FOO(p, 1u);
BAR(p, 1);
BAR(p, 1u);
return 0;
}
0
typedef struct ll_node
{
struct ll_node *prev;
struct ll_node *next;
int val;
} ll_node;
ll_node a;
ll_node b;
ll_node c = {&a, &b,3};
// не работает
a.next = &b;
a.prev = &c;
b.next = &c;
b.prev = &a;
/*
c.next = &a;
c.prev = &b;
*/
// зато так работает:
ll_node arr[3] = {
{&arr[2], &arr[1],1},
{&arr[0], &arr[2],2},
{&arr[1], &arr[0],3}
};
Кольцевой двусвязный список.
+1
Почему при таком обилии языков программирования ассемблер не уходит в туман?
К нему возвращаются опять и опять, и, что удивительно, тем чаще, чем язык высокоуровневей.
Напоминает попытки быдла бросить курить.
0
// https://godbolt.org/z/f4s13WEWM
#include <inttypes.h>
int test(uint32_t a, uint32_t b)
{
if (a > b)
return a+b;
return a*b;
}
int test2(uint32_t a, uint32_t b)
{
return (a+b)*(a > b) | (a*b)*!(a > b);
}
int test3(uint32_t a, uint32_t b)
{
return
((a+b) & (uint32_t)(!(a > b) - 1)) |
((a*b) & (uint32_t)((a > b) - 1));
}
int test4(uint32_t a, uint32_t b)
{
const uint32_t arr[2] = {a+b, a*b};
return arr[!(a > b)];
}
/* ASM output
test:
bltu a1, a0, .LBB0_2
mul a0, a1, a0
ret
.LBB0_2:
add a0, a0, a1
ret
test2:
bltu a1, a0, .LBB1_2
mul a0, a1, a0
ret
.LBB1_2:
add a0, a0, a1
ret
test3:
bltu a1, a0, .LBB2_2
mul a0, a1, a0
ret
.LBB2_2:
add a0, a0, a1
ret
test4:
addi sp, sp, -16
add a2, a1, a0
mul a3, a1, a0
sltu a0, a1, a0
sw a2, 8(sp)
sw a3, 12(sp)
xori a0, a0, 1
slli a0, a0, 2
addi a1, sp, 8
add a0, a0, a1
lw a0, 0(a0)
addi sp, sp, 16
ret
*/
Наглядная демонстрация того, что компилятор может насрать на ваши попытки заставить его сгенерить branchless машинный код. Получилось это только в "test4"
0
extern char* strcat( char* dest, const char* src );
extern int printf ( const char * restrict format, ... );
extern int putchar( int ch );
#define LISPER(n, l, re) ({ \
auto int ii = l; \
static unsigned char n[l]; \
while (ii--) { \
*str##n(n, (unsigned char[]){0x09 >> 1 << 1, 0x1911 >> 0xD}); \
}; \
*((void**)&re) = printf((unsigned char[]){0x25, 0x73, 0x1917 >> 0xE}, n); \
})
struct bombitterLemon{
union {
unsigned char : 0;
unsigned char : 0;
unsigned char v: 7;
} pacific;
};
int main(void) {
struct bombitterLemon b0;
LISPER(cat, 0x40 ^ (2 << 2), b0);
(*putchar) (*(struct wtf**)&b0);
LISPER(cat, ((int) (((char*) (0x8 ^ (1 << 6))) - 3) | 1), b0);
(**putchar) (*(struct is***)&b0);
LISPER(cat, ((int) (((short*) (0x9 << 3))) | 4), b0);
(***putchar) (*(struct that****)&b0);
LISPER(cat, ((int) (((int*) (0x12 << 2))) | 4), b0);
(**putchar) (*(unsigned char*****)&b0);
LISPER(cat, ((int) (((long*) (0x90 >> 1))) | 4 | 2 | 1), b0);
(*putchar) (b0.pacific.v);
}
Классический собесный говнокод для кунов на громкие позиции malware ANALyst, security дрист-searcher и даже (о, ужас) compiler devteam в известные шарашки.
Шланг<15 и ICC жуют с говном не глядя. Чего не сказать о бычаре, дристающего на коврик.
Осилил, анонимус? Поясни пацанам на пальцах за высер без единого include с ноября прошлого.