- 1
- 2
- 3
- 4
- 5
- 6
void MultMatrix(const GLfloat m1[16], const GLfloat m2[16], GLfloat result[16])
{
glLoadMatrixf(m1);
glMultMatrixf(m2);
glGetFloatv(GL_MODELVIEW_MATRIX, result);
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+6
void MultMatrix(const GLfloat m1[16], const GLfloat m2[16], GLfloat result[16])
{
glLoadMatrixf(m1);
glMultMatrixf(m2);
glGetFloatv(GL_MODELVIEW_MATRIX, result);
}
+5
catch(...)
{
static int i = 0;
//if we enter this catch clause more than 1 time
//it is very likely that the RestartSystem() command
//did not succeed. If this is the case we just exit.
if(i>0)
exit(0);
else
MonitorT::GetInstance()->RestartSystem();
i++;
throw;
}
Навеяло...
+6
// implicit_cast< >
// I believe this was originally going to be in the C++ standard but
// was left out by accident. It's even milder than static_cast.
// I use it instead of static_cast<> to emphasize that I'm not doing
// anything nasty.
// Usage is identical to static_cast<>
template <class OutputClass, class InputClass>
inline OutputClass implicit_cast(InputClass input){
return input;
}
// horrible_cast< >
// This is truly evil. It completely subverts C++'s type system, allowing you
// to cast from any class to any other class. Technically, using a union
// to perform the cast is undefined behaviour (even in C). But we can see if
// it is OK by checking that the union is the same size as each of its members.
// horrible_cast<> should only be used for compiler-specific workarounds.
// Usage is identical to reinterpret_cast<>.
// This union is declared outside the horrible_cast because BCC 5.5.1
// can't inline a function with a nested class, and gives a warning.
template <class OutputClass, class InputClass>
union horrible_union{
OutputClass out;
InputClass in;
};
template <class OutputClass, class InputClass>
inline OutputClass horrible_cast(const InputClass input){
horrible_union<OutputClass, InputClass> u;
// Cause a compile-time error if in, out and u are not the same size.
// If the compile fails here, it means the compiler has peculiar
// unions which would prevent the cast from working.
typedef int ERROR_CantUseHorrible_cast[sizeof(InputClass)==sizeof(u)
&& sizeof(InputClass)==sizeof(OutputClass) ? 1 : -1];
u.in = input;
return u.out;
}
Боль и страдание шаблонного программирования на С++98. Комменты и названия доставляют.
+1
$res2=CSaleBasket::GetList(array(), array(
"PRODUCT_ID"=>$record["PRODUCT_ID"],
"!ORDER_ID"=>0
));
$reserverY = array("N", "A", "C", "B", "D", "P", "R", "S", "T", "E");
while($record2=$res2->GetNext()){
$ordNext = CSaleOrder::GetList(array(), array("ID"=>$record2['ORDER_ID']))->GetNext();
if(in_array($ordNext['STATUS_ID'], $reserverY) && $ordNext['CANCELED'] != 'Y')
{
$product["QUANTITY_RESERVED"] += $record2['QUANTITY'];
}
}
0
void checklock(globalMemManager *c)
{
if (!c->isThread) return;
_voidint idl=c->isThread();
#ifdef THREADDEBUG
assert(idl!=0);
#endif
while (idl==0 && c->lock());
if (idl!=0) while (true) {
while (c->lockId()!=idl) {
c->canLeave()=idl;
}
if (c->lock()) break;
}
c->lock()=true;
}
void unlock(globalMemManager *c)
{
if (!c->isThread) return;
c->lock()=false;
#ifdef THREADDEBUG
assert(c->lockId()==c->isThread());
#endif
c->canLeave()=0;
c->lockId()=0;
}
void globalMemManager::manage()
{
if (!lock()) if (lockId()==0 && canLeave()!=0) {
if (!lock()) lock()=true;
lockId()=canLeave();
}
}
Лучшее
−2
namespace bt {
#define MEMNULL \
_FORCEINLINE void* operator new(size_t) { return 0; } \
_FORCEINLINE void operator delete(void* ) { }
#define MEMDEFAULT(classname) \
_FORCEINLINE void* operator new(size_t size) { return extFunctions.CreateMem((unsigned int)size, 0); } \
_FORCEINLINE void operator delete(void* val) { extFunctions.DeleteMem(val, 0); }
#define MEMMANAGER(classname) \
_FORCEINLINE void* operator new(size_t size) { return bt::internalmemmanager.getNew((unsigned int)size); } \
_FORCEINLINE void operator delete(void* val) {bt::internalmemmanager.freeThis(val,sizeof(classname));}
#define MEMMANAGERCLEAN(classname) \
_FORCEINLINE void* operator new(size_t size) { return bt::internalmemmanager.getNewClean((unsigned int)size); } \
_FORCEINLINE void operator delete(void* val) { bt::internalmemmanager.freeThis(val,sizeof(classname)); }
class memManagerExport {
public:
MEMDEFAULT(memManagerExport)
BT_API memManagerExport(unsigned int size);
BT_API virtual ~memManagerExport();
/// destroy all memory segments and free list of free pointers
BT_API void _free();
/// return pointer to new object and create new segment of objects if need.
BT_API void *_addAlloc();
/// return pointer to free object
BT_API void *_getFree(unsigned int size);
/// add pointer to list of free
BT_API void _appendToFree(_voidint idat);
/// mark pointer to free ???
BT_API void _markFree(void* val);
/// return number object in segment
BT_API unsigned int _valid(unsigned int id);
/// return segment number
BT_API unsigned int _segid(unsigned int id);
/// prepare calculation for object size
BT_API void _calcsize(unsigned int size);
private:
enum States {
VALIDED = 0x011F1C01,
FREE = 0
};
unsigned int fisVal;
struct p_smemManager *fargs;
};
class memManager: public memManagerExport {
public:
MEMDEFAULT(memManager)
_FORCEINLINE memManager(unsigned int size):memManagerExport(size) {}
_FORCEINLINE ~memManager() {}
/// create memory for object
_FORCEINLINE void *getNew(unsigned int size) {return (void*)_getFree(size);}
/// delete memory for object
_FORCEINLINE void freeThis(void * val) {_appendToFree((_voidint)val);}
/// destroy all memory segments and free list of free
_FORCEINLINE void free() {_free();};
};
class globalMemManager {
public:
MEMDEFAULT(globalMemManager)
}
Давайте ржать
+7
private bool trap = false;
public bool TrapExceptions
{
get { return this.trap; }
set { this.trap = true; }
}
Выхода нет.
−1
#ifndef H112
#define H112 201004L
#include<iostream>
#include<fstream>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<list>
#include<vector>
#include<algorithm>
#include<stdexcept>
//------------------------------------------------------------------------------
#ifdef _MSC_VER
#include <hash_map>
using stdext::hash_map;
#else
#include <ext/hash_map>
using __gnu_cxx::hash_map;
namespace __gnu_cxx {
template<> struct hash<std::string>
{
size_t operator()(const std::string& s) const
{
return hash<char*>()(s.c_str());
}
};
} // of namespace __gnu_cxx
#endif
//------------------------------------------------------------------------------
#define unordered_map hash_map
//------------------------------------------------------------------------------
typedef long Unicode;
//------------------------------------------------------------------------------
using namespace std;
template<class T> string to_string(const T& t)
{
ostringstream os;
os << t;
return os.str();
}
struct Range_error : out_of_range { // enhanced vector range error reporting
int index;
Range_error(int i) :out_of_range("Range error: "+to_string(i)), index(i) { }
};
// trivially range-checked vector (no iterator checking):
template< class T> struct Vector : public std::vector<T> {
typedef typename std::vector<T>::size_type size_type;
Vector() { }
explicit Vector(size_type n) :std::vector<T>(n) {}
Vector(size_type n, const T& v) :std::vector<T>(n,v) {}
template <class I>
Vector(I first, I last) :std::vector<T>(first,last) {}
T& operator[](unsigned int i) // rather than return at(i);
{
if (i<0||this->size()<=i) throw Range_error(i);
return std::vector<T>::operator[](i);
}
const T& operator[](unsigned int i) const
{
if (i<0||this->size()<=i) throw Range_error(i);
return std::vector<T>::operator[](i);
}
};
// disgusting macro hack to get a range checked vector:
#define vector Vector
// trivially range-checked string (no iterator checking):
struct String : std::string {
String() { }
String(const char* p) :std::string(p) {}
String(const string& s) :std::string(s) {}
template<class S> String(S s) :std::string(s) {}
String(int sz, char val) :std::string(sz,val) {}
template<class Iter> String(Iter p1, Iter p2) : std::string(p1,p2) { }
char& operator[](unsigned int i) // rather than return at(i);
{
if (i<0||size()<=i) throw Range_error(i);
return std::string::operator[](i);
−89
КолЯ= ЦЕЛ(колБутДлчЯщ/20) ;
колЯщ=колЯЩ+ КолЯ;
если колЯ< колБутДлчЯщ/20 Тогда
колЯщ= колЯщ+1;
конецЕсли;
Что будет, если пустить в конфигуратор беременную женщину? В коде окажется Коля.
−4
<Style>
html { overflow: visible !important; }
</Style>
CSS конечно, но...