954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

warning: assignment makes pointer from integer without a cast

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.

asilter
Junior Poster in Training
60 posts since Oct 2006
Reputation Points: 10
Solved Threads: 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;
}
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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);
asilter
Junior Poster in Training
60 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

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

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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.

Hamrick
Posting Whiz
325 posts since Jun 2007
Reputation Points: 180
Solved Threads: 34
 

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.

TkTkorrovi
Junior Poster
170 posts since Mar 2005
Reputation Points: 85
Solved Threads: 13
 

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

asilter
Junior Poster in Training
60 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

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

asilter
Junior Poster in Training
60 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

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?

SphinCorp
Newbie Poster
3 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You