-
Лучший говнокод
- В номинации:
-
- За время:
-
-
+23
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
struct S* gpS;
struct S
{
// this class has no user-defined default ctor
void *operator new (size_t size, void*p, int i)
{
((S*)p)->i = i; // ordinarily, should not initialize
// memory contents inside placement new
return p;
}
int i;
};
Код с сайта майкрософт.
LispGovno,
09 Января 2013
-
+23
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
#include <iostream>
using namespace std;
class Class {
public:
explicit Class(int a) : m_int(a) {}
int get() const { return m_int; }
void swapThis(int a) {
delete this;
Class **thisptr = reinterpret_cast<Class**>(&a);
thisptr--;
*thisptr = new Class(a);
cout << "this: " << this << endl
<< "that: " << *thisptr << endl;
}
private:
int m_int;
};
int main() {
Class *s = new Class(13);
s->swapThis(42);
cout << s->get() << endl;
delete s;
return 0;
}
Что творит хакингкостылинг + инлайн методы.
http://ideone.com/5Kyitw
Elvenfighter,
29 Декабря 2012
-
+23
- 1
- 2
typedef const AbstractParameter ConstAbstractParameter;
class Parameter: public ConstAbstractParameter{
GCC это не компилирует, но в 2008 ms vs компилируется без предупреждений. Я это как увидел, так сразу переписал на
class Parameter: public AbstractParameter{
А вот теперь я дома и не могу заснуть. Гложет чувство, что я поступил не правильно. Такое чувство как-будто этот const, пусть и не в рамках стандарта С++, но что-то он делал.
LispGovno,
20 Ноября 2012
-
+23
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
#include <iostream>
#include <stdlib.h>
#include <typeinfo>
using namespace std;
#define ololo for(volatile register int i=0;i<10;++i);
struct VB
{
virtual void f() const =0;
};
class V1: public VB
{
void f() const {ololo}
};
class V2: public VB
{
void f() const {ololo}
};
struct TU1
{
inline void f() const {ololo}
};
struct TU2
{
inline void f() const {ololo}
};
struct TUB
{
const type_info* type;
union
{
TU1 tu1;
TU2 tu2;
};
template<class T>
void ctor()
{
this->type=&typeid(T);
}
template<class T>
inline void call(const T& f)
{
if(this->type==&typeid(TU1))
f(this->tu1);
else
f(this->tu2);
}
};
enum {N=1000, N2=N*50};
int main() {
cout<<"ok"<<endl;
{
VB*v[N];
for(int i=0;i<N;++i)
if(rand()%2)
v[i]=new V1;
else
v[i]=new V2;
volatile clock_t a=clock();
for(int j=0;j<N2;++j)
for(int i=0;i<N;++i)
v[i]->f();
volatile clock_t b=clock();
cout<< (double)(b - a) / CLOCKS_PER_SEC<<endl;
}
cout<<"ok"<<endl;
{
TUB v[N];
for(int i=0;i<N;++i)
if(rand()%2)
v[i].ctor<TU1>();
else
v[i].ctor<TU2>();
struct Continuation
{
inline void operator()(const TU1& a) const {a.f();}
inline void operator()(const TU2& a) const {a.f();}
} cps;
volatile clock_t a=clock();
for(int j=0;j<N2;++j)
for(int i=0;i<N;++i)
v[i].call(cps);
volatile clock_t b=clock();
cout<< (double)(b - a) / CLOCKS_PER_SEC<<endl;
}
cout<<"ok"<<endl;
return 0;
}
http://ideone.com/plFaLM
Тут в соседней теме разгорелся спор, что быстрее - полиморфизм виртуальных функций или полиморфизм tagget union. По сути последнее - выбор по if нужной виртуальной функции. Говорят в Java быстрее второе.
Тема родилась из http://govnokod.ru/12025#comment158188
Получилось по результатам измерений:
Виртуальные функции: 1.8 секунд.
tagget union: 1.94 секунд.
Притом это всего 2 полиморфных типа в tagget union, а если рост числа полиморфных классов будет расти, то разрыв между виртуальными функциями и tagget union только увеличится. Притом производительность tagget union будет только падать.
Тема поднята ещё со взглядом на функциональные языки. Это ведь там так модны ADT с постоянным внутри ifподобным паттернматчингом по ним.
Жду указания на косяки или способы поднять производительность tagget union.
LispGovno,
31 Октября 2012
-
+23
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
%:include <iostream>
int main(int argc, char *argv<::>)
<%
if (argc > 1 and argv<:1:> not_eq '\0') <%
std::cout << "Hello " << argv<:1:> << '\n';
%>
std::cout<<"ko"<<std::endl;
%>
??=include <iostream>
int main(int argc, char *argv??(??))
??<
if (argc > 1 and argv??(1??) not_eq '\0') ??<
std::cout << "Hello " << argv??(1??) << '\n';
??>
std::cout<<"ko"<<std::endl;
??>
http://liveworkspace.org/code/150ad59b81b309bbffed963829f4fc9e
http://liveworkspace.org/code/c64104e4272af4d89f2f74c35c5c2ee3
Просто оставлю это здесь.
HaskellGovno,
20 Августа 2012
-
+23
- 1
QHash<QByteArray, QSharedPointer<KeywordAnalyzerResult::Statistics> >::const_iterator i = res.result()->constBegin();
Создание STL-style итератора для Qt-ных контейнеров обычно выглядит уродски.
viktorious,
10 Августа 2012
-
+23
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
const Tifon& Tifon::operator=(const Tifon& Buffer)
{
assert(&Buffer!=this);
if(&Buffer==this)
return *this;
Tifon OldForExceptionSafe(*this);
try{
this->~Tifon();
::new((void*)this)Tifon(Buffer);
}catch(...){//try restore
::new((void*)this)Tifon(OldForExceptionSafe);
}
return *this;
};
//...
namespace std
{
const Tifon&swap (Tifon& a, Tifon& b) {
assert(&a!=&b);
if(&a==&b)
return a;
Tifon c(a);
a=b;
b=c;
}
};
USB,
22 Июля 2012
-
+23
- 1
- 2
if(this==NULL)
return;
HaskellGovno,
04 Июля 2012
-
+23
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
<?php
class AppController extends Controller {
var $uses = array('Config', "Cats");
function beforeFilter()
{
$config1 = $this->Config->find('list', array('fields'=>array('key', 'value')));
$category1 = $this->Cats->findAll();
$this->set(compact('config1'));
$this->set(compact('category1'));
}
}
?>
тупой код =)
guest,
23 Января 2009
-
+23
Кусочек из одного похек скрипта
guest,
19 Января 2009