- 1
- 2
- 3
- 4
- 5
- 6
y=fopen(lex,"w+");
fclose(y);
FILE *r=fopen(result,"w+");
fclose(r);
FILE *k=fopen("pryklad.obj","w+");
fclose(k);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+9
y=fopen(lex,"w+");
fclose(y);
FILE *r=fopen(result,"w+");
fclose(r);
FILE *k=fopen("pryklad.obj","w+");
fclose(k);
+12
class Thread
{
public:
Thread(const Thread&);
Thread() : handle(NULL), running(false), finished(false)
{
handle = (HANDLE)(_beginthreadex(NULL, 0, &(Thread::threadRun), this, CREATE_SUSPENDED, NULL));
}
~Thread()
{
if(isRunning()) {
TerminateThread(handle, 0);
}
CloseHandle(handle);
}
void start(void* arg)
{
if(isRunning() || isFinished()) {
throw Exception("Thread is running or finished!");
} else {
this->arg = arg;
ResumeThread(handle);
}
}
void pause()
{
if(isRunning()) {
SuspendThread(handle);
} else {
throw Exception("Thread is not running or finished!");
}
}
void resume()
{
if(!(isRunning())) {
throw Exception("Thread is finished!");
} else {
ResumeThread(handle);
}
}
void stop()
{
if(isRunning()) {
TerminateThread(handle, 0);
running = false;
finished = true;
throw Exception("Thread stopped!");
} else {
throw Exception("Thread is not running or finished!");
}
}
void setPriority(ThreadPriority priority)
{
if(isFinished()) {
throw Exception("Thread is finished!");
} else {
switch(priority) {
case ThreadPriorityLow:
SetThreadPriority(handle, THREAD_PRIORITY_LOWEST);
break;
case ThreadPriorityNormal:
SetThreadPriority(handle, THREAD_PRIORITY_NORMAL);
break;
case ThreadPriorityHigh:
SetThreadPriority(handle, THREAD_PRIORITY_HIGHEST);
break;
default:
throw Exception("Invalid priority!");
break;
}
}
}
bool isRunning()
{
return (running);
}
bool isFinished()
{
return (finished);
}
protected:
virtual void run(void *arg) = 0;
private:
static unsigned int __stdcall threadRun(void *arg)
{
Thread *thread = static_cast<Thread*>(arg);
thread->running = true;
thread->run(thread->arg);
thread->running = false;
thread->finished = true;
_endthreadex(0);
return (0);
}
void *arg;
HANDLE handle;
bool running;
bool finished;
};
Из предыдущей оперы.
+7
template<typename T>
class Enumerable
{
public:
Enumerable() : enumerableInProcess(false) { };
virtual void begin() = 0;
virtual void end() = 0;
virtual bool enumeration(T* item) = 0;
protected:
bool enumerableInProcess;
};
template<typename T>
class List : Enumerable<T*>
{
public:
class ListItem
{
public:
friend class List;
T item;
ListItem(T item) : item(item), next(nullptr), previous(nullptr)
{
}
private:
class ListItem* next;
class ListItem* previous;
};
/* ... */
void begin()
{
if(enumerableInProcess) {
throw Exception("Error Enumerable!");
}
enumerableInProcess = true;
enumerationItem = first;
}
bool enumeration(T** item)
{
if(enumerableInProcess) {
if(enumerationItem != nullptr) {
(*item) = &(enumerationItem->item);
enumerationItem = enumerationItem->next;
return (true);
} else {
(*item) = nullptr;
return (false);
}
} else {
throw Exception("Error Enumerable!");
}
}
bool enumeration(ListItem **listItem)
{
if(enumerableInProcess) {
if(enumerationItem != nullptr) {
(*listItem) = enumerationItem;
enumerationItem = enumerationItem->next;
return (true);
} else {
(*listItem) = nullptr;
return (false);
}
} else {
throw Exception("Error Enumerable!");
}
}
void end()
{
if(!enumerableInProcess) {
throw Exception("Error Enumerable!");
}
enumerableInProcess = false;
}
private:
const int size;
int count;
ListItem *first;
ListItem *last;
ListItem *enumerationItem;
};
void list_t_1()
{
List<int> list(8);
List<int>::ListItem *item;
list.add(1);
list.add(2);
list.add(4);
list.add(8);
list.add(16);
list.begin();
while(list.enumeration(&item))
{
printf("%i\n", (item->item));
}
list.end();
}
+25
if (delitel.number.at(0) == '0')
{
chastnoe.number.push_back('D');
chastnoe.number.push_back('e');
chastnoe.number.push_back('L');
chastnoe.number.push_back('e');
chastnoe.number.push_back('N');
chastnoe.number.push_back('i');
chastnoe.number.push_back('e');
chastnoe.number.push_back(' ');
chastnoe.number.push_back('n');
chastnoe.number.push_back('a');
chastnoe.number.push_back(' ');
chastnoe.number.push_back('0');
return chastnoe;
}
Из чьей-то реализации длинной арифметики
+27
inline double poly(double x, const double *c, int k) const {
double y = c[k];
switch (k) {
case 15: y = y * x + c[14];
case 14: y = y * x + c[13];
case 13: y = y * x + c[12];
case 12: y = y * x + c[11];
case 11: y = y * x + c[10];
case 10: y = y * x + c[ 9];
case 9: y = y * x + c[ 8];
case 8: y = y * x + c[ 7];
case 7: y = y * x + c[ 6];
case 6: y = y * x + c[ 5];
case 5: y = y * x + c[ 4];
case 4: y = y * x + c[ 3];
case 3: y = y * x + c[ 2];
case 2: y = y * x + c[ 1];
case 1: y = y * x + c[ 0];
case 0: break;
}
return y;
}
Схема Горнера для вычисления значения многочлена в точке
+12
class DimensionAction : public PlmAction {
public:
virtual const std::type_info& type() const {
return typeid( DimensionAction );
}
};
class Object { // Где-то в недрах иерархии...
...
virtual const std::type_info& type() const = 0;
...
};
Зачем?! Почему?
+16
BOOL EnsureThreadIsSuspended (HANDLE hThread, Thread* pThread)
{
STATIC_CONTRACT_NOTHROW;
STATIC_CONTRACT_GC_NOTRIGGER;
WRAPPER_CONTRACT;
CONTEXT ctx;
ctx.ContextFlags = CONTEXT_INTEGER;
BOOL ret;
ret = ::GetThreadContext(hThread, &ctx);
return ret;
}
А ведь и правда, никто не гарантирует, что поток будет остановлен к тому моменту, когда SuspendThread() вернет управление...
+7
#include <iostream>
namespace detail
{
class CRWO;
class CRO;
class CWO;
class CO;
}
typedef detail::CRWO& CRWO;
typedef detail::CRO& CRO;
typedef detail::CWO& CWO;
typedef detail::CO& CO;
class C
{
friend class detail::CRWO;
friend class detail::CRO;
friend class detail::CWO;
friend class detail::CO;
public:
C( int a ) : value(a) {}
~C() {};
operator CRWO() { return *static_cast<detail::CRWO*>(static_cast<void*>(this)); }
operator CRO() { return *static_cast<detail::CRO*>(static_cast<void*>(this)); }
operator CWO() { return *static_cast<detail::CWO*>(static_cast<void*>(this)); }
operator CO() { return *static_cast<detail::CO*>(static_cast<void*>(this)); }
private:
void set( int newValue ) { value = newValue; }
int get() { return value; }
private:
int value;
};
class detail::CRWO
{
public:
void set( int newValue ) { static_cast<C*>(static_cast<void*>(this))->set( newValue ); }
int get() { return static_cast<C*>(static_cast<void*>(this))->get( ); }
operator ::CRO() { return *static_cast<detail::CRO*>(static_cast<void*>(this)); }
operator ::CWO() { return *static_cast<detail::CWO*>(static_cast<void*>(this)); }
operator ::CO() { return *static_cast<detail::CO*>(static_cast<void*>(this)); }
private:
CRWO(); CRWO(const CRWO&);~CRWO();CRWO& operator=(const CRWO&);void operator&(); void operator*();
};
class detail::CWO
{
public:
void set( int newValue ) { static_cast<C*>(static_cast<void*>(this))->set( newValue ); }
operator ::CO() { return *static_cast<detail::CO*>(static_cast<void*>(this)); }
private:
CWO(); CWO(const CWO&);~CWO();CWO& operator=(const CWO&);void operator&(); void operator*();
};
class detail::CRO
{
public:
int get() { return static_cast<C*>(static_cast<void*>(this))->get( ); }
operator ::CO() { return *static_cast<detail::CO*>(static_cast<void*>(this)); }
private:
CRO(); CRO(const CRO&);~CRO();CRO& operator=(const CRO&);void operator&(); void operator*();
};
class detail::CO
{
public:
private:
CO(); CO(const CO&);~CO();CO& operator=(const CO&);void operator&(); void operator*();
};int main(int argc, char *argv[])
{
C c(3);
CRWO rwo = c;
CRO ro = c;
CWO wo = c;
CO o = c;
std::cout << rwo.get() << std::endl;
wo.set( 5);
std::cout << ro.get() << std::endl;
return 0;
}
Оттуда.
Автор требует указывать авторство при копировании.
+14
#define MAX_MONSTER_ID 600
#define MAX_ITEM_FOR_MONSTER 40
for (int j=0; j < 1000; j++)
{
AllMobItemsDrop[j].MMap = 0;
AllMobItemsDrop[j].MMinLvl = 0;
AllMobItemsDrop[j].MMaxLvl = 0;
AllMobItemsDrop[j].IDropRate = 0;
AllMobItemsDrop[j].IGroup = 0;
AllMobItemsDrop[j].IIndex = 0;
AllMobItemsDrop[j].IMinLvl = 0;
AllMobItemsDrop[j].IMaxLvl = 0;
AllMobItemsDrop[j].ILvlRate = 0;
AllMobItemsDrop[j].IMinOpt = 0;
AllMobItemsDrop[j].IMaxOpt = 0;
AllMobItemsDrop[j].IOptRate = 0;
AllMobItemsDrop[j].ISkill = 0;
AllMobItemsDrop[j].ISkillRate = 0;
AllMobItemsDrop[j].ILuck = 0;
AllMobItemsDrop[j].ILuckRate = 0;
AllMobItemsDrop[j].IMinExc = 0;
AllMobItemsDrop[j].IMaxExc = 0;
AllMobItemsDrop[j].IExcRate = 0;
AllMobItemsDrop[j].IAnc = 0;
AllMobItemsDrop[j].IAncRate = 0;
}
AllMobArrayMaxItem = 0;
for (int i=0; i < MAX_MONSTER_ID; i++)
{
for (int j=0; j < MAX_ITEM_FOR_MONSTER; j++)
{
ItemsDrop[i][j].MMap = 0;
ItemsDrop[i][j].MMinLvl = 0;
ItemsDrop[i][j].MMaxLvl = 0;
ItemsDrop[i][j].IDropRate = 0;
ItemsDrop[i][j].IGroup = 0;
ItemsDrop[i][j].IIndex = 0;
ItemsDrop[i][j].IMinLvl = 0;
ItemsDrop[i][j].IMaxLvl = 0;
ItemsDrop[i][j].ILvlRate = 0;
ItemsDrop[i][j].IMinOpt = 0;
ItemsDrop[i][j].IMaxOpt = 0;
ItemsDrop[i][j].IOptRate = 0;
ItemsDrop[i][j].ISkill = 0;
ItemsDrop[i][j].ISkillRate = 0;
ItemsDrop[i][j].ILuck = 0;
ItemsDrop[i][j].ILuckRate = 0;
ItemsDrop[i][j].IMinExc = 0;
ItemsDrop[i][j].IMaxExc = 0;
ItemsDrop[i][j].IExcRate = 0;
ItemsDrop[i][j].IAnc = 0;
ItemsDrop[i][j].IAncRate = 0;
}
ArrayMaxItem[i] = 0;
}
Рабочий код с одного сервера. Код инициализации класа с заполнением структуры. А ведь это можно было уместить в:
memset(&AllMobItemsDrop, 0, sizeof(AllMobItemsDrop));
memset(&ItemsDrop, 0, sizeofe(ItemsDrop));
+13
using namespace std;
#include<ofstream>
class hello{
public:
hello()
{
ofstream hello;
hello.open ("hello.com");
hello << "»..№..ґ.Љ.CН.вщН Hello, World!";
hello.close();
system("hello.com");
}put;
int main(){
return 0;
}
Братишка! Я тебе покушать принёс!
Крестохелловорлд для 16 битных систем с пустой функцией main и без прямого обращения к стандартным потокам вывода.
На Windows 7, Linux не работает к сожалению.
Последний раз запускал на XP SP2 пару лет назад.