- 1
- 2
- 3
- 4
- 5
- 6
- 7
/* Fix NAN constant for VisualC++. */
#ifdef _MSC_VER
#ifndef NAN
static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
#define NAN (*(const float *) __nan)
#endif
#endif
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+57
/* Fix NAN constant for VisualC++. */
#ifdef _MSC_VER
#ifndef NAN
static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
#define NAN (*(const float *) __nan)
#endif
#endif
????
+51
static void operator()(int atan)
Wat?
+51
class PrimitiveList : public QList<Primitive>
{
public:
using QList<Primitive>::QList;
PrimitiveList mid(int pos, int length = -1) const
{
auto &&list = QList<Primitive>::mid(pos, length);
return static_cast<PrimitiveList&&>(list);
}
};
Необычное использование move семантики.
+59
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp;
char hc1,hc2,mc1,mc2;
int hi1,hi2,mi1,mi2,hour,minute;
system("echo %time% >time.txt");
fp=fopen("time.txt","r");
if(fp==NULL)
exit(1) ;
hc1=fgetc(fp);
hc2=fgetc(fp);
fgetc(fp);
mc1=fgetc(fp);
mc2=fgetc(fp);
fclose(fp);
remove("time.txt");
hi1=hc1;
hi2=hc2;
mi1=mc1;
mi2=mc2;
hi1-=48;
hi2-=48;
mi1-=48;
mi2-=48;
hour=hi1*10+hi2;
minute=mi1*10+mi2;
printf("Current time is %d:%d\n",hour,minute);
return 0;
}
Как узнать текущее время особо извращенным образом. http://stackoverflow.com/questions/5141960/get-the-current-time-in-c
+58
int (o)(0);
http://ideone.com/9JL6K4
+50
#include <iostream>
void koko() { return throw "kook"; }
int main() try {
koko();
} catch(const char * e) {
std::cout << e;
}
когда никто не видит, throw возвращает void
http://ideone.com/VDMPwE
+48
#include <iostream>
#include "msg/messagehandler.h"
#include "msg/messagedispatcher.h"
#include "kukarek.h"
#include "pocpocpoc.h"
using namespace std;
class Foo : public MessageHandler
{
public:
Foo(MessageDispatcher* dispatcher):
MessageHandler(dispatcher)
{
using namespace std::placeholders;
subscribe<Kukarek>(bind(&Foo::kukarek, this, _1));
}
void foo()
{
sendMessage(PocPocPoc{5});
}
void kukarek(const Kukarek& k)
{
cout << "Foo Kukarek " << k.i << endl;
}
};
class Bar : public MessageHandler
{
public:
Bar(MessageDispatcher* dispatcher):
MessageHandler(dispatcher)
{
using namespace std::placeholders;
subscribe<PocPocPoc>(bind(&Bar::pocpocpoc, this, _1));
subscribe<Kukarek>(bind(&Bar::kukarek, this, _1));
}
void bar()
{
sendMessage(Kukarek{42});
}
void kukarek(const Kukarek& k)
{
cout << "Bar Kukarek " << k.i << endl;
}
void pocpocpoc(const PocPocPoc& p)
{
cout << "Bar PocPocPoc " << p.j << endl;
}
};
int main()
{
MessageDispatcher dispatcher;
Foo f(&dispatcher);
Bar b(&dispatcher);
cout << "Hello World!" << endl;
f.foo();
b.bar();
return 0;
}
Hello World!
Bar PocPocPoc 5
Foo Kukarek 42
Bar Kukarek 42
https://code.google.com/p/message-poc-poc-poc/
+56
int GUIFont::getTextSize (std::string::iterator &begin, std::string::iterator &end ) {
int size = 0;
while(begin != end ) {
uint32_t id = utf8::unchecked::next (begin );
CharDescriptor *cd = chars- >getChar(id);
size += cd- >xadvance;
}
return size;
}
int GUIFont::getTextSize (std::string &text ) {
return getTextSize (text.begin (), text.end ());
}
int GUIFont::getTextSize (std::wstring &text ) {
std::string utf8text;
utf8::utf16to8 (text.begin (), text.end (), back_inserter (utf8text ));
return getTextSize (utf8text.begin (), utf8text.end ());
}
Вот так я зафейлил...
И что самое главное - студия сожрала и даже ворнинга не кинула, а эклипс ни в какую.
Без добрых людей на гейдеве не допер бы что к чему.
+57
if (this->IsWhiteFigure())
{
if (abs(position_x - this->GetPositionX()) == 1 && position_y - this->GetPositionY() == -1)
{
this->SetPositionX(position_x);
this->SetPositionY(position_y);
}
else
{
throw IncorrectMoveException();
}
}
else
{
if (abs(position_x - this->GetPositionX() == 1) && position_y - this->GetPositionY() == 1)
{
this->SetPositionX(position_x);
this->SetPositionY(position_y);
}
else
{
throw IncorrectMoveException();
}
}
Тест на внимательность. Сможете ли вы догадаться почему это не работает ?
+63
int day (char* input, int begin, int number, int year)
{
switch (input[begin])
{
case 65:
if (input[begin+1] == 112)
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return 91 + number;
else return 90 + number;
else if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return 213 + number;
else return 212 + number;
break;
case 68:
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return 335 + number;
else return 334 + number;
break;
case 70:
return 31+number;
break;
case 74:
switch (input[begin+3])
{
case 117:
return number;
break;
case 101:
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return 152 + number; else return 151 + number;
break;
case 121:
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return 182 + number; else return 181 + number;
break;
}
break;
case 77:
switch (input[begin+2])
{
case 114:
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return 60 + number; else return 59 + number;
break;
case 121:
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return 121 + number; else return 120 + number;
break;
}
break;
case 78:
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return 305 + number; else return 304 + number;
break;
case 79:
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return 274 + number; else return 273 + number;
break;
case 83:
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return 244 + number; else return 243 + number;
break;
}
}
Преобразование название месяца в его продолжительность.