- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
#include <iostream>
using namespace std;
int main() {
// your code goes here
float f = 267.0f;
unsigned char c = f;
cout << (int)c << endl;
return 0;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+63
#include <iostream>
using namespace std;
int main() {
// your code goes here
float f = 267.0f;
unsigned char c = f;
cout << (int)c << endl;
return 0;
}
Кресты помогают обнаруживать ошибки в логике программы. За это Страуструпу респект и уважуха.
http://ideone.com/V9rgSC
+125
var
generalPtr : Pointer; // Указатель на что-нибудь
formPtr : ^TForm; // Указатель на объект формы
begin
// Форма текущего модуля адресуемая через ключевое слово self
generalPtr := Addr(self);
// Мы можем присвоить этот указатель указателю формы
formPtr := generalPtr;
// И установить заголовок формы, чтобы показать это
formPtr.Caption := 'Test program';
end;
Форма будет показана с з[color=red]а[/color]галовком:
Test program
http://www.delphibasics.ru/Pointer.php
+131
#include <stdio.h>
#include <stdlib.h>
/*
Declare array of functions that return array of functions with
one parameter - function accepting array of functions returning
a pointer to function void(void). No typedefs.
Decoded to the following:
1) An array of E.
2) E = a function that takes void and returns an array of D (returns an array taken to mean a pointer to D).
3) D = a function that takes C and returns void.
4) C = a function that takes an array of B and returns void.
5) B = a function that takes void and returns A.
6) A = a pointer to void(void).
*/
/* Using typedefs */
typedef void (*tA) (void);
typedef tA (*tB) (void);
typedef void (*tC) (tB b[]);
typedef void (*tD) (tC c);
typedef tD* (*tE) (void);
tE tArray[2];
/* Not using typedefs */
void (*_A) (void);
void (* (*_B) (void) ) (void);
void (*_C) ( void (* (*_B[]) (void) ) (void) );
void (*_D) ( void (*_C) ( void (* (*_B[]) (void) ) (void) ) );
void (** (*_E) (void) ) ( void (*_C) ( void (* (*_B[]) (void) ) (void) ) );
void (** (*_Array[2]) (void) ) ( void (*_C) ( void (* (*_B[]) (void) ) (void) ) );
/* Some concrete functions for testing */
void fA(void)
{
printf("fA\n");
}
tA fB(void)
{
printf("fB\n");
return &fA;
}
void fC(tB b[])
{
tA _a;
printf("fC\n");
_a = (*b[0])();
(*_a)();
}
void fD(tC c)
{
tB b[1];
printf("fD\n");
b[0] = &fB;
(*c)(b);
}
tD* fE(void)
{
tD *d;
printf("fE\n");
d = malloc(sizeof(tD));
d[0] = &fD;
return d;
}
int main()
{
tA _a;
tB _b;
tC _c;
tD _d;
tE _e;
tB b[1];
tD *d;
_a = &fA;
_A = &fA;
printf("_a\n");
(*_a)();
printf("_A\n");
(*_A)();
_b = &fB;
_B = &fB;
printf("_b\n");
_a = (*_b)();
(*_a)();
printf("_B\n");
_a = (*_B)();
(*_a)();
_c = &fC;
_C = &fC;
b[0] = _b;
printf("_c\n");
(*_c)(b);
printf("_C\n");
(*_C)(b);
_d = &fD;
_D = &fD;
printf("_d\n");
(*_d)(&fC);
printf("_D\n");
(*_D)(&fC);
_e = &fE;
_E = &fE;
printf("_e\n");
d = (*_e)();
(*d[0])(&fC);
free(d);
printf("_E\n");
d = (*_E)();
(*d[0])(&fC);
free(d);
printf("tArray\n");
tArray[0] = &fE;
d = (*tArray[0])();
(*d[0])(&fC);
free(d);
printf("_Array\n");
_Array[0] = &fE;
d = (*_Array[0])();
(*d[0])(&fC);
free(d);
return 0;
}
+139
#define BPP_AES_SHIFT_ROWS_II(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
(a)(f)(k)(p)(e)(j)(o)(d)(i)(n)(c)(h)(m)(b)(g)(l)
Навеяно http://govnokod.ru/14511
Welcome to the macro hell: https://github.com/bormand/pp_aes
+128
mixin template GenerateAutoDispose()
{
void dispose()
{
foreach_reverse(i,t;this.tupleof)
{
static if(staticIndexOf!(auto_dispose,__traits(getAttributes, this.tupleof[i])) != -1)
{
static if(isArray!(typeof(t)))
{
foreach(t1;t)
{
if(t1 !is null)
{
t1.dispose();
}
}
}
else
{
if(t !is null)
{
t.dispose();
}
}
}
}
}
}
http://pastebin.com/2x2k7ngR
+63
int main()
{
server::CServer();
return 0;
}
class CServer {
public:
CServer()
{
SOCKET listen_sd = socket (AF_INET, SOCK_STREAM, 0); CHK_ERR(listen_sd, "socket");
SET_NONBLOCK(listen_sd);
struct sockaddr_in sa_serv;
memset (&sa_serv, '\0', sizeof(sa_serv));
sa_serv.sin_family = AF_INET;
sa_serv.sin_addr.s_addr = INADDR_ANY;
sa_serv.sin_port = htons (1111); /* Server Port number */
int err = ::bind(listen_sd, (struct sockaddr*) &sa_serv, sizeof (sa_serv)); CHK_ERR(err, "bind");
err = listen (listen_sd, 5); CHK_ERR(err, "listen");
while(true)
{
Sleep(1);
struct sockaddr_in sa_cli;
size_t client_len = sizeof(sa_cli);
#ifdef WIN32
const SOCKET sd = accept (listen_sd, (struct sockaddr*) &sa_cli, (int *)&client_len);
#else
const SOCKET sd = accept (listen_sd, (struct sockaddr*) &sa_cli, &client_len);
#endif
Callback(sd);
}
}
};
http://habrahabr.ru/post/211853/
Бесконечный цикл (event loop) в конструкторе.
Опущены неинтересные строчки инициализации всякой фигни.
Про Sleep вместо select/epoll/etc. я вовсе молчу.
+56
#include <iostream>
using namespace std;
int main() {
int i = 5;
int* p1 = &i;
volatile int* p2 = &i;
cout << p1 << endl;
cout << p2 << endl;
return 0;
}
http://ideone.com/hpw4CB
+74
class A {}
class B {}
class C {
public void m(A a, B b) {
/* ... */
if ((Object) a != (Object) b) { /* ... */ }
}
}
Да здравствуют неочевидности! По-нормальному же нельзя писать :)
+74
JSONObject jonReady = props.getObject(MessageType.Keys.onReady);
Who is John Ready?
+137
System.Drawing.Color.FromArgb(((int)(((byte)(249)))), ((int)(((byte)(249)))), ((int)(((byte)(249)))));