I did not care on warnings. But they put me in trouble lately.
When compiler comes to the statement below it gives the warning.

/* void ** vpSec00 comes as an argument */
int hSec = 0;
size_t nbytes;
*vpSec00 = bitio_o_close(hSec0, &nbytes);

it says:
warning: assignment makes pointer from integer without a cast

if i cast it as :

/* void ** vpSec00 comes as an argument */
*vpSec00 = (void *) bitio_o_close(hSec0, &nbytes);

it says:
warning: cast to pointer from integer of different size

bitio_o_close function returns char array as:

return (void *) bios[handle].buf;

why would i need casting here? Because Salem said that I should stay away from redundant casting in function returns.

Compiled without errors/warnings with my compiler -- VC++ 2005 Express as both a C and a C++ program. What compiler are you using ? Does your compiler complain about the below ?

char* foo1()
{
    return (char *)malloc(255);
}

int foo(void **vpSec00)
{
    
    *vpSec00 = foo1();
    return 0;
}

Compiled without errors/warnings with my compiler -- VC++ 2005 Express as both a C and a C++ program. What compiler are you using ? Does your compiler complain about the below ?

char* foo1()
{
    return (char *)malloc(255);
}
 
int foo(void **vpSec00)
{
 
    *vpSec00 = foo1();
    return 0;
}

i'm using :
gcc (GCC) 3.3.3 (SuSE Linux)

it says :
warning: cast to pointer from integer of different size

for the line :

return (char *)malloc(255);

maybe you need to get the newest version of that compiler ??? I don't use it, so don't know.

You need to include stdlib.h. The error cryptically tells you that malloc wasn't declared and the compiler just assumes it's a function that returns int and casting from int to char* isn't friendly.

commented: Excellent diagnosis of the problem +9

I included stdlib.h, and my compiler doesn't give any warning, even with all warnings on. Without stdlib h it says "incompatible implicit declaration of built-in function 'malloc'" gcc 4.1.2, debian linux.

commented: Yes +9

i've included stdlib.h but the warning is still there. maybe i need to upgrade to gcc 4.1.2.

i've heard that type casting warnings are not so important.

I have the same problem with:

page_directory[0] = page_table;

where

unsigned long *page_directory = (unsigned long *) 0x9C000;
unsigned long *page_table = (unsigned long *) 0x9D000;

Note that this is to initialize paging at kernel level, so stdlib.h is NOT an option, as malloc() -- a memory allocation function -- is to be part of the memory manager this calls. how would I explicitly type-cast that?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.