- 1
- 2
- 3
- 4
- 5
- 6
CharT getline(std::istream& i, string& s, const CharT* delim) {
...
if (!i.operator void*())
break;
...
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+2
CharT getline(std::istream& i, string& s, const CharT* delim) {
...
if (!i.operator void*())
break;
...
}
Библиотека Apache UIMA-CPP.
Что могло заставить написать так, вместо обычного if (i)? Какой-то древний компилятор, который не использует каст к указателю в условии?
Ну и, разумеется, в C++11 ios::operator void*() заменили на explicit ios::operator bool(), так что работать перестало.
+1
void Game::Loadlevel(int which){
stealthloading=0;
if(which==0)Loadlevel((char *)":Data:Maps:map1");
else if(which==1)Loadlevel((char *)":Data:Maps:map2");
else if(which==2)Loadlevel((char *)":Data:Maps:map3");
// [...]
}
// [Почему (char *)? Да вот же!]
void Game::Loadlevel(char *name){
int i,j,k,l,m;
static int oldlevel;
int templength;
float lamefloat;
int lameint;
// [...]
}
Ебём const машиной Тьюринга. Всё тот же https://hg.icculus.org/icculus/lugaru/file/97b303e79826/Source/GameTick.cpp , прямо-таки сокровищница с говном.
+4
if(((player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim)||player[i].skeleton.free)&&((player[k].targetanimation!=getupfrombackanim&&player[k].targetanimation!=getupfromfrontanim)||player[k].skeleton.free))
if(((((findLengthfast(&rotatetarget)>150&&(i!=0&&k!=0))||(findLengthfast(&rotatetarget)>50&&player[0].rabbitkickragdoll/*currentanimation==rabbitkickanim*/&&(i==0||k==0)))&&normaldotproduct(rotatetarget,player[k].coords-player[i].coords)>0)&&((i==0||k==0)||((player[i].skeleton.oldfree==1&&k!=0&&animation[player[k].currentanimation].attack==neutral)||(player[k].skeleton.oldfree==1&&i!=0&&animation[player[i].currentanimation].attack==neutral)||(player[i].isFlip()&&!player[i].skeleton.oldfree&&(i==0||k==0))||(player[k].isFlip()&&!player[k].skeleton.oldfree&&(i==0||k==0))||(i==0||k==0))))||((player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip())&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&(i==0||k==0)&&(!player[i].skeleton.oldfree&&!player[k].skeleton.oldfree))){
//If hit by body
if((i!=0||player[i].skeleton.free)&&(k!=0||player[k].skeleton.free)||(animation[player[i].targetanimation].height==highheight&&animation[player[k].targetanimation].height==highheight)){
static float gLoc[3];
// ...
Не могу не запостить. Кажется, это самый длинный говнокод, что я видел.
По мотиву #20073, из http://hg.icculus.org/icculus/lugaru/file/97b303e79826/Source/GameTick.cpp .
PS, на всякий случай поставлю C++ - где-то в недрах второй строчки он наверняка есть.
+6
for(int i = 0; i < codes.size(); ++i) {
switch(i) {
case 0: ret.code0 = codes[i]; break;
case 1: ret.code1 = codes[i]; break;
case 2: ret.code2 = codes[i]; break;
case 3: ret.code3 = codes[i]; break;
case 4: ret.code4 = codes[i]; break;
case 5: ret.code5 = codes[i]; break;
}
}
А всё потому, что ret.code[0-5] - битовые поля. Эх.
+5
//Collisions
static float collisionradius;
if(numplayers>1)
for(k=0;k<numplayers;k++){
for(i=k;i<numplayers;i++){
if(i==k)i++;
if(i<numplayers)
if((animation[player[i].targetanimation].attack!=reversed&&animation[player[i].targetanimation].attack!=reversal&&animation[player[k].targetanimation].attack!=reversed&&animation[player[k].targetanimation].attack!=reversal)||(i!=0&&k!=0))
if((animation[player[i].currentanimation].attack!=reversed&&animation[player[i].currentanimation].attack!=reversal&&animation[player[k].currentanimation].attack!=reversed&&animation[player[k].currentanimation].attack!=reversal)||(i!=0&&k!=0))
if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
if(i!=k&&player[i].whichpatchx==player[k].whichpatchx&&player[i].whichpatchz==player[k].whichpatchz&&player[k].skeleton.oldfree==player[k].skeleton.free&&player[i].skeleton.oldfree==player[i].skeleton.free&&player[i].targetanimation!=climbanim&&player[i].targetanimation!=hanganim&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim)
if(player[i].coords.y>player[k].coords.y-3)
if(player[i].coords.y<player[k].coords.y+3)
if(player[i].coords.x>player[k].coords.x-3)
if(player[i].coords.x<player[k].coords.x+3)
if(player[i].coords.z>player[k].coords.z-3)
if(player[i].coords.z<player[k].coords.z+3){
if(findDistancefast(&player[i].coords,&player[k].coords)<3*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)){
if(player[i].onfire||player[k].onfire){
if(!player[i].onfire)player[i].CatchFire();
if(!player[k].onfire)player[k].CatchFire();
}
}
...
http://hg.icculus.org/icculus/lugaru/file/97b303e79826/Source/GameTick.cpp#l7276
+9
#define GetLastError rand /* optimize API work */
#define struct union /* saves memory */
#define while if /* saves cpu time */
+4
string TRASETXT::trace(string &a // получаемая строка )
{
string b; // возвращаемая строка
stringstream s; // строковый поток
// переводит в втооом словосочетании все большие буквы в маленькие
for (unsigned int i = 0; i < a.size(); i++) // а - получаемая строка
{
int key = a[i];
if ((key <= -33) && (key >= -64)) // от А до Я
key += 32;
if (key == -88) // только буква Ё
key = -72;
if ((key >= 65) && (key <= 90)) // от A до Z
key += 32;
s << (char)key;
}
getline(s, b); // получаем строку только из маленьких букв во временную переменную
s.clear(); // очищаем поток
return b;
}
Увидел в курсаче у чувака, лучший метод преобразования строки в lowercase, везде буду использовать теперь и вам рекомендую
0
u_long thisIp = htonl(this->sockaddr.sin_addr.S_un.S_addr);
u_long otherIp = htonl(other.sockaddr.sin_addr.S_un.S_addr);
u_short thisPort = htons(this->sockaddr.sin_port);
u_short otherPort = htons(other.sockaddr.sin_port);
// ip1 + port1 < ip2 + port2
if (thisIp < otherIp)
{
if (thisPort <= otherPort)
{
return true;
}
else
{
return ((unsigned)(thisPort - otherPort) < (unsigned)(otherIp - thisIp));
}
}
else
{
if (thisPort >= otherPort)
{
return false;
}
else
{
return ((unsigned)(thisIp - otherIp) < (unsigned)(otherPort - thisPort));
}
}
Сравнить IPv4 адрес + порт. Т.е., по сути, (thisIP + thisPort) < (otherIP + otherPort).
unsigned long long, приди!
+3
bool Object::DeleteDouble(void* data)
{
Element* rc = Head;
BANKCLIENT* asd = (BANKCLIENT*)rc->Data;
int dbl;
Element* rc1 = Head;
BANKCLIENT* asd1 = (BANKCLIENT*)rc1->Data;
while ((rc != NULL) && (rc->Data != data))
{
asd = (BANKCLIENT*)rc->Data;
dbl = asd->NumScore;
while ((rc1 != NULL) && (rc1->Data != data))
{
asd1 = (BANKCLIENT*)rc1->Data;
if (dbl == asd1->NumScore)
{
std::cout << "Дублирующийся элемент удалён" << std::endl;
Delete(rc1);
goto flag;
}
}
}
flag:
system("pause");
return rc;
}
Некая svetlana.kotik раскрывает секреты односвязных списков.
−2
#include <iostream>
#include <cstdlib>
#include <windows.h>
#include <string>
using namespace std;
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
cout << "Привет, я твой личный собеседник на ближайшие 40 секунд. Мое имя Компьютер" << endl;
string *greeting = new string;
cin >> greeting;
if (greeting == "Привет" || greeting == "Здравствуйте" || greeting == "Приветствую" || greeting == "привет" || greeting == "да" || greeting == "Да" || greeting == "здравствуйте" || greeting == "приветствую")
cout << "Как Вас зовут?" << endl;
else
while (greeting == "Привет" || greeting == "Здравствуйте" || greeting == "Приветствую" || greeting == "привет" || greeting == "да" || greeting == "Да" || greeting == "здравствуйте" || greeting == "приветствую");
{
cout << "Давайте начнем с приветствия" << endl;
cin >> greeting;
}
}
Nobody can help me now