Fix compiler warnings in examples when using -std=c++98 -std=gnu89 -pedantic -Wreturn-type

This commit is contained in:
William S Fulton 2014-05-24 00:14:01 +01:00
commit f39ed94419
43 changed files with 75 additions and 73 deletions

View file

@ -13,7 +13,7 @@ void sort_int(int* arr, int len)
qsort(arr, len, sizeof(int), compare_int);
}
// ditto doubles
/* ditto doubles */
int compare_double(const void * a, const void * b)
{
return (int)( *(double*)a - *(double*)b );

View file

@ -45,14 +45,14 @@ void testModule(lua_State *L)
swig_type_info *pTypeInfo=0,*pTypeInfo2=0;
swig_module_info *pModule=0;
pModule=SWIG_GetModule(L);
DEBUG2(" SWIG_GetModule() returns %p\n",pModule)
DEBUG2(" SWIG_GetModule() returns %p\n", (void *)pModule)
if(pModule==0) return;
pTypeInfo = SWIG_TypeQuery(L,"Foo *");
DEBUG2(" Type (Foo*) is %s\n",pTypeInfo==0?"unknown":"known");
DEBUG3(" Module %p typeinfo(Foo*) %p\n",pModule,pTypeInfo);
DEBUG3(" Module %p typeinfo(Foo*) %p\n", (void *)pModule, (void *)pTypeInfo);
pTypeInfo2 = SWIG_TypeQuery(L,"Bar *");
DEBUG2(" Type (Bar*) is %s\n",pTypeInfo2==0?"unknown":"known");
DEBUG3(" Module %p typeinfo(Bar*) %p\n",pModule,pTypeInfo2);
DEBUG3(" Module %p typeinfo(Bar*) %p\n", (void *)pModule, (void *)pTypeInfo2);
}
int main(int argc,char* argv[])

View file

@ -53,7 +53,7 @@ int call_add(lua_State *L,int a,int b,int* res) {
lua_getglobal(L, "add"); /* function to be called */
if (!lua_isfunction(L,-1)) {
printf("[C] error: cannot find function 'add'\n");
lua_settop(L,top); // reset
lua_settop(L,top);
return 0;
}
lua_pushnumber(L,a);
@ -61,18 +61,18 @@ int call_add(lua_State *L,int a,int b,int* res) {
if (lua_pcall(L, 2, 1, 0) != 0) /* call function with 2 arguments and 1 result */
{
printf("[C] error running function `add': %s\n",lua_tostring(L, -1));
lua_settop(L,top); // reset
lua_settop(L,top);
return 0;
}
// check results
/* check results */
if (!lua_isnumber(L,-1)) {
printf("[C] error: returned value is not a number\n");
lua_settop(L,top); // reset
lua_settop(L,top);
return 0;
}
*res=(int)lua_tonumber(L,-1);
lua_settop(L,top); /* reset stack */
return 1; // ok
return 1;
}
/* This is a variargs call function for calling from C into Lua.

View file

@ -1,13 +1,12 @@
/* File : example.i */
%module example
%include "typemaps.i" // you must have this for the typemaps for ptrs
// basic function testing
//
%include "typemaps.i"
%inline %{
extern int add1(int x, int y); // return x+y -- basic function test
extern void add2(int x, int *INPUT, int *OUTPUT); // *z = x+*y -- argin and argout test
extern int add3(int x, int y, int *OUTPUT); // return x+y, *z=x-y -- returning 2 values
extern void add4(int x, int *INOUT); // *y += x -- INOUT dual purpose variable
extern int add1(int x, int y); /* return x+y -- basic function test */
extern void add2(int x, int *INPUT, int *OUTPUT); /* *z = x+*y -- argin and argout test */
extern int add3(int x, int y, int *OUTPUT); /* return x+y, *z=x-y -- returning 2 values */
extern void add4(int x, int *INOUT); /* *y += x -- INOUT dual purpose variable */
%}

View file

@ -39,12 +39,15 @@ Square* createSquare(double w)
return new Square(w);
}
ShapeOwner::ShapeOwner() {printf(" ShapeOwner(%p)\n",this);}
ShapeOwner::ShapeOwner() {
printf(" ShapeOwner(%p)\n", (void *)this);
}
ShapeOwner::~ShapeOwner()
{
printf(" ~ShapeOwner(%p)\n",this);
for(unsigned i=0;i<shapes.size();i++)
delete shapes[i];
printf(" ~ShapeOwner(%p)\n", (void *)this);
for(unsigned i=0;i<shapes.size();i++)
delete shapes[i];
}
void ShapeOwner::add(Shape* ptr) // this method takes ownership of the object

View file

@ -52,9 +52,9 @@ void print_vars() {
printf("cvar = %c\n", cvar);
printf("strvar = %s\n", strvar ? strvar : "(null)");
printf("cstrvar = %s\n", cstrvar);
printf("iptrvar = %p\n", iptrvar);
printf("iptrvar = %p\n", (void *)iptrvar);
printf("name = %s\n", name);
printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0);
printf("ptptr = %p (%d, %d)\n", (void *)ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0);
printf("pt = (%d, %d)\n", pt.x, pt.y);
printf("status = %d\n", status);
}