- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
#include <stdio.h>
int main(void)
{
int a = a;
printf("%d", a);
return 0;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
#include <stdio.h>
int main(void)
{
int a = a;
printf("%d", a);
return 0;
}
Убрал ворнинг. Проверь.
https://tio.run/##S9ZNT07@/185My85pzQlVcGmuCQlM18vw46LKzOvRCE3MTNPoyw/M0WTq5pLAQhAgokKtgqJ1mBuQRFQIE1DSTVFSUchURMiWJRaUlqUp2BgzVXL9f//v@S0nMT04v@64Yk5OQA
0
// https://github.com/ghc/ghc/blob/e204431e5a5e2fd16da52b04bda2798f16c51344/rts/Interpreter.c#L1184
case bci_PUSH8: {
int off = BCO_NEXT;
Sp_subB(1);
*(StgWord8*)Sp = *(StgWord8*)(Sp_plusB(off+1));
goto nextInsn;
}
case bci_PUSH16: {
int off = BCO_NEXT;
Sp_subB(2);
*(StgWord16*)Sp = *(StgWord16*)(Sp_plusB(off+2));
goto nextInsn;
}
case bci_PUSH32: {
int off = BCO_NEXT;
Sp_subB(4);
*(StgWord32*)Sp = *(StgWord32*)(Sp_plusB(off+4));
goto nextInsn;
}
case bci_PUSH8_W: {
int off = BCO_NEXT;
*(StgWord*)(Sp_minusW(1)) = *(StgWord8*)(Sp_plusB(off));
Sp_subW(1);
goto nextInsn;
}
case bci_PUSH16_W: {
int off = BCO_NEXT;
*(StgWord*)(Sp_minusW(1)) = *(StgWord16*)(Sp_plusB(off));
Sp_subW(1);
goto nextInsn;
}
case bci_PUSH32_W: {
int off = BCO_NEXT;
*(StgWord*)(Sp_minusW(1)) = *(StgWord32*)(Sp_plusB(off));
Sp_subW(1);
goto nextInsn;
}
https://ghc.haskell.org/trac/ghc/wiki/Commentary/Rts/Interpreter
> The linker lives in rts/Linker.c and is responsible for handling runtime loading of code into a Haskell process. This is something of a big blob of unpleasant code, and see DynamicGhcPrograms for information about efforts to reduce our dependence on this linker.
Итак, тут у нас стековая машина из хачкеля, которая вродекак отвечает за динамическую загрузку какого-то говна.
0
// https://github.com/alpertron/calculators/blob/15607feafb0ddb1c075bb326dc6ea2224a4c50bb/siqs.c#L3720
switch (NumberLengthA)
{
case 7:
dRem = (double)*(piDividend + 6) * (double)rowPrimeTrialDivisionData->exp6 +
(double)*(piDividend + 5) * (double)rowPrimeTrialDivisionData->exp5 +
(double)*(piDividend + 4) * (double)rowPrimeTrialDivisionData->exp4 +
(double)*(piDividend + 3) * (double)rowPrimeTrialDivisionData->exp3 +
(double)*(piDividend + 2) * (double)rowPrimeTrialDivisionData->exp2 +
(double)*(piDividend + 1) * (double)rowPrimeTrialDivisionData->exp1;
break;
case 6:
dRem = (double)*(piDividend + 5) * (double)rowPrimeTrialDivisionData->exp5 +
(double)*(piDividend + 4) * (double)rowPrimeTrialDivisionData->exp4 +
(double)*(piDividend + 3) * (double)rowPrimeTrialDivisionData->exp3 +
(double)*(piDividend + 2) * (double)rowPrimeTrialDivisionData->exp2 +
(double)*(piDividend + 1) * (double)rowPrimeTrialDivisionData->exp1;
break;
case 5:
dRem = (double)*(piDividend + 4) * (double)rowPrimeTrialDivisionData->exp4 +
(double)*(piDividend + 3) * (double)rowPrimeTrialDivisionData->exp3 +
(double)*(piDividend + 2) * (double)rowPrimeTrialDivisionData->exp2 +
(double)*(piDividend + 1) * (double)rowPrimeTrialDivisionData->exp1;
break;
case 4:
dRem = (double)*(piDividend + 3) * (double)rowPrimeTrialDivisionData->exp3 +
(double)*(piDividend + 2) * (double)rowPrimeTrialDivisionData->exp2 +
(double)*(piDividend + 1) * (double)rowPrimeTrialDivisionData->exp1;
break;
default:
dRem = (double)*(piDividend + 2) * (double)rowPrimeTrialDivisionData->exp2 +
(double)*(piDividend + 1) * (double)rowPrimeTrialDivisionData->exp1;
break;
}
Generic two integer variable equation solver
This calculator can solve equations of the form ax² + bxy + cy² + dx + ey + f = 0 where the unknowns x and y are integer numbers.
0
// https://git.zx2c4.com/BruteZip/tree/read.c?id=e4e9c17b99e0d108136b8a07632b1ebaa7d09d28#n26
int main(int argc, char *argv[])
{
union {
long int l;
char c[sizeof(long int)];
} u;
u.l = 1;
if (u.c[sizeof(long int) - 1] == 1) {
printf("This program only runs on little endian archs, because I'm lazy. Sorry.\n");
return -2;
}
Хуйня какая-то. Ведь sizeof(long int) может быть равен sizeof(char).
Но над такой питушней обычно никто не задумывается
−1
// http://p99.gforge.inria.fr/p99-html/group__flexible.html
//C99 allows a flexible array member to be defined as the last member of a struct,
// namely an array of undetermined length.
//P99_DECLARE_STRUCT(package_head);
struct package_head {
char name[20];
size_t len;
uint64_t data[];
};
// Such a struct can then be allocated on the heap with a suitable size such
// that the field data has as many elements as fit in the allocated space from
// the start of data onward. Usually one would allocate such struct with
package_head *a = malloc(sizeof(package_head) + 10 * sizeof(uint64_t));
package_head *b = malloc(sizeof(*b) + 12 * sizeof(b->data[0]));
// This has several disadvantages. Firstly, the syntax is clumsy. We have to
// use a relatively complicated expression that uses two elements of the specification of a or b.
// Secondly, it wastes space. Due to packing of the struct the offset of data "inside"
// the struct may be less than sizeof(package_head). In most cases the real size
// of the object that we want to construct is
offsetof(package_head, data) + N * sizeof(uint64_t)
// so we are wasting
sizeof(package_head) - offsetof(package_head, data)
// bytes.
// The above formula for the exact size is only valid for larger values of N. We must
// also ensure that we allocate at least sizeof(package_head) bytes. So the complete
// formula looks something like
#define P99_FSIZEOF(T, F, N) P99_MAXOF(sizeof(T), offsetof(T, F) + P99_SIZEOF(T, F[0]) * N)
// which is probably not something that you want to write on a daily basis.
// We provide several interfaces to allocate struct with flexible members
Херню написали какую-то. Забыли самое главное : нельзя так в лоб аллоцировать память под структуры. Потому что выравнивание может не то быть.
Надо использовать http://man7.org/linux/man-pages/man3/aligned_alloc.3.html
−1
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
int main(void)
{
char a[8], b[8];
char *a_ptr = a+8;
char *b_ptr = b;
printf("a_ptr = %p, b_ptr = %p\n", a_ptr, b_ptr);
if (a_ptr != b_ptr)
{
printf("a_ptr != b_ptr\n");
}
else
{
printf("a_ptr == b_ptr\n");
}
if ((uintptr_t)a_ptr != (uintptr_t)b_ptr)
{
printf("(uintptr_t)a_ptr != (uintptr_t)b_ptr\n");
}
else
{
printf("(uintptr_t)a_ptr == (uintptr_t)b_ptr\n");
}
return EXIT_SUCCESS;
}
Что по-вашему тут происходит?
+2
/*
* Place the right command in the parameter AY temperature fine adjust
* Uses number from PPD less 11.
*/
switch (header->cupsCompression)
{
case 1 :
strcpy(Fadjt,"{AY;-10,");
break;
case 2 :
strcpy(Fadjt,"{AY;-09,");
break;
case 3 :
strcpy(Fadjt,"{AY;-08,");
break;
case 4 :
strcpy(Fadjt,"{AY;-07,");
break;
case 5 :
strcpy(Fadjt,"{AY;-06,");
break;
case 6 :
strcpy(Fadjt,"{AY;-05,");
break;
case 7 :
strcpy(Fadjt,"{AY;-04,");
break;
case 8 :
strcpy(Fadjt,"{AY;-03,");
break;
case 9 :
strcpy(Fadjt,"{AY;-02,");
break;
case 10 :
strcpy(Fadjt,"{AY;-01,");
break;
case 11 :
strcpy(Fadjt,"{AY;+00,");
break;
case 12 :
strcpy(Fadjt,"{AY;+01,");
break;
case 13 :
strcpy(Fadjt,"{AY;+02,");
break;
case 14 :
strcpy(Fadjt,"{AY;+03,");
break;
case 15 :
strcpy(Fadjt,"{AY;+04,");
break;
case 16 :
strcpy(Fadjt,"{AY;+05,");
break;
case 17 :
strcpy(Fadjt,"{AY;+06,");
break;
case 18 :
strcpy(Fadjt,"{AY;+07,");
break;
case 19 :
strcpy(Fadjt,"{AY;+08,");
break;
case 20 :
strcpy(Fadjt,"{AY;+09,");
break;
case 21 :
strcpy(Fadjt,"{AY;+10,");
break;
}
+2
void add_SSE(uint8_t a[static 7], uint8_t b[static 7], uint8_t out[static 7])
{
uint64_t a_64 = 0;
uint64_t b_64 = 0;
for (size_t i = 0; i < 7; i++) // можно наанроллить
{
a_64 |= (uint64_t)a[i] << (i*9);
b_64 |= (uint64_t)b[i] << (i*9);
}
uint64_t c_64 = a_64 + b_64;
for (size_t i = 0; i < 7; i++) // можно наанроллить
{
out[i] = (uint64_t)c_64 >> (i*9);
}
}
SSE
−3
void print_line(char *s){
for(int i = 0; i < strlen(s); i++) putchar(s[i]);
putchar('\n');
}
Почему C работает медленнее чем JavaScript ?
−1
void sort8(uint64_t a[8])
{
uint64_t a0;
uint64_t a1;
uint64_t a2;
uint64_t a3;
uint64_t a4;
uint64_t a5;
uint64_t a6;
uint64_t a7;
SORT2(a[0], a[1], a0, a1);
SORT2(a[2], a[3], a2, a3);
SORT2(a[4], a[5], a4, a5);
SORT2(a[6], a[7], a6, a7);
uint64_t a_tmp[8];
MERGE_2_4(a0, a1, a2, a3, a_tmp[0], a_tmp[1], a_tmp[2], a_tmp[3]);
MERGE_2_4(a4, a5, a6, a7, a_tmp[4], a_tmp[5], a_tmp[6], a_tmp[7]);
uint64_t *ptra1 = &a_tmp[0];
uint64_t *ptra2 = &a_tmp[4];
for (size_t i = 0; i < 4; i++)
{
if (*ptra1 < *ptra2)
{
a[i] = *ptra1;
ptra1++;
}
else
{
a[i] = *ptra2;
ptra2++;
}
}
for (size_t i = 4; i < 8; i++)
{
if (ptra1 == &a_tmp[4])
{
while (ptra2 != &a_tmp[8])
{
a[i++] = *ptra2;
ptra2++;
}
break;
}
if (ptra2 == &a_tmp[8])
{
while (ptra1 != &a_tmp[4])
{
a[i++] = *ptra1;
ptra1++;
}
break;
}
if (*ptra1 < *ptra2)
{
a[i] = *ptra1;
ptra1++;
}
else
{
a[i] = *ptra2;
ptra2++;
}
}
}
Мерж сорт, специализированный на 8 элементов. Вот доказательство корректности https://paste.debian.net/hidden/cce6d31a/