NO

Author Topic: C compiler conventions  (Read 2253 times)

Adamanteus

  • Guest
C compiler conventions
« on: February 17, 2008, 02:29:38 pm »
 Attached file that's giving wrong warnings and not compiling if uncomment last line !
 Small remark about povars32.bat - last line is better : if not "%1." == "." cd %1

JohnF

  • Guest
Re: C compiler conventions
« Reply #1 on: February 17, 2008, 03:08:21 pm »
I've corrected a few things and made it more readable (IMO), see if this code will satisfy.

Code: [Select]
#include "stdio.h"
#include "windows.h"

size_t memavail(void)
{
return GetFreeSpace(0);
}

typedef unsigned long grant;

char gucmp(const grant * number1, const grant * number2)
{
if (number1[1] > number2[1])
return 1;
else if (number1[1] < number2[1])
return -1;
else if ((number1[0]) > (number2[0]))
return 1;
else if ((number1[0]) < (number2[0]))
return -1;
else
return 0;
}

char *stristalk(const char *string, const char sim)
{
unsigned char *substr = (unsigned char *)(string + strlen(string));
while ((void *)substr != (void *)string)
{ // BUG !
substr--;
if (*substr > (unsigned char)sim)
return (char *)substr;
};
return NULL;
}

char *test = "y bug\t!";

int main(void)
{
grant x[2] = { 1, 1 }, y[2] = { 2, 2 };
puts(stristalk(test, 'x'));
while (gucmp(x, y) > 0){}
return 0;
}

John
« Last Edit: February 17, 2008, 03:24:20 pm by JohnF »