typedef signed int sint;
#define N 100
static int n = N;
inline int f(const int n, int& i, int* j, int t[2], int p=11)
{
i*=i;
(*j)--;
if ( n<=0 )
{
cout << ::n << ">\n";
return t[0];
}
else return f(n-1, i, j, t) + t[n];
}
int main()
{
int n = 4;
int x = 1U;
sint y = 10;
int (*fptr)(const int, int&, int*, int*, int) = f;
int* t = new int[n];
int& r = *(t+3);
(*t) = 1;
*(t+1) = 2;
t[2] = 3;
r = 4;
int z = (*fptr)(5, x, &y, t, 12);
for(int i = 0; i < 2*n; i++)
{
if( i == n )
continue;
if( i > n )
break;
cout << t[i] << "\n";
};
cout << x << ", " << y << ", " << z << "\n";
delete[] t;
}
This is what my professor gave as part of the final exam. The purpose of giving us this code was to get us used to seeing different ways the C++ syntax can be used and figure out what the output is.
int file_exist(){
FILE *file;
if((file = fopen(SCORE_FILE_NAME, "r"))){
fclose(file);
return 1;
}
return 0;
}
char * dataFunc(){
TCHAR tc[256];
LONG tc_len = sizeof(tc);
getData((LPBYTE)&tc, &tc_len);
char * data = new char[tc_len];
for(int i = 0;i < tc_len;i++)
data[i] = tc[i];
return data;
}
// Test read access of memory
try
{
c = ( (char*) pvMemory )[0];
c = ( (char*) pvMemory )[iNLen - 1];
}
catch( ... ) {
return -1;
}
for (int i = 0;i < n / 2;i++)
{
while (num[a[p].id].n == 0 || num[num[a[p].id].nxt].n == 0)
{
p++;
}
printf("%d %d ", num[a[p].id].n, num[num[a[p].id].nxt].n);
num[a[p].id].n = 0;
num[num[a[p].id].nxt].n = 0;
num[num[a[p].id].lst].nxt = num[num[a[p].id].nxt].nxt;
num[num[num[a[p].id].nxt].nxt].lst = num[a[p].id].lst;
}
ierr = pxmlIn->GetData(pcTag, *pTData);
*pbDataValid = bool((ierr==0)&&(iLen>0)); // enabled if: not empty string and vaild (number?)
if (*pbDataValid) iErr += ierr;
#define private public
#define protected public
#define class struct
#include "your_private_parts.hpp"
// ...
#undef class
#undef protected
#undef private
// ...
Fails miserably if template <class>
, template <template <class> class>
or their variations are found anywhere inside your header.
:(
void MagicUnit::getSomeVoltage(std::uint64_t w_data, double &val)
{
std::uint64_t r_data = 0;
hwRead((int)Address::Voltage, 3, w_data, 2, &r_data);
val = r_data;
val /= 16; // shit right 4 bits
val *= 0.004;
val -= 8.192;
}
double zuida(std::vector<double> vec) {
std::vector<double> temp;
for(int i = 0; i < vec.size(); i++)
temp.push_back(vec[i]);
notend:
if(temp.size() > 0) {
if(temp.size() < 2) {
double tmp = *(&temp[0]);
return tmp;
}
else if(temp.size() >= 2) {
double mini = temp[0];
int ind = 0;
for(int i = 0; i < temp.size(); i++)
if(temp[i] < mini) {
mini = temp[i];
ind = i;
}
temp.erase(temp.begin() + ind);
goto notend;
}
}
}
The beauty is that every case is the best (also worst) case!
auto settingsFileSize = static_cast<int>(sizeof(_settings));
This was in release branch for a month. Casting wasn't even necessary.
if(!strncmp(pcTagName,strlim,(int)strlen(strlim))) return "";
void winner(int score[4])
{
if (score[0] > score[1] > score[2] > score[3])
cout << "The winner is the Player 1 with " << score[0] << " points.";
else if (score[1] > score[0] > score[2] > score[3])
cout << "The winner is the Player 2 with " << score[1] << " points.";
else if (score[2] > score[0] > score[1] > score[3])
cout << "The winner is the Player 3 with " << score[2] << " points.";
else if (score[3] > score[2] > score[1] > score[0])
cout << "The winner is the Player 4 with " << score[3] << " points.";
}
if ((&inactiveSlot)->GetFirstSlot() == RuntimeLib::INVALID_SLOT) {
Dot dude...
string sum_numbers(string a, string b) {
char ca, cb, ci, out, co = '0';
string result = "";
while (a.size() > 0 || b.size() > 0 || co != '0') {
ci = co; ca = '0'; cb = '0';
if (a.size() > 0) {ca = a.back(); a.pop_back();}
if (b.size() > 0) {cb = b.back(); b.pop_back();}
result = ((((ca != cb) ? '1' : '0') != ci) ? '1' : '0') + result;
co = ((((ca == '1' && cb == '1') ? '1' : '0') == '1' ||
((((ca != cb) ? '1' : '0') == '1' && ci == '1') ? '1' : '0') == '1') ? '1' : '0');
}
return result;
}
Scary stuff