Search code examples
c32bit-64bitgcc-warning

Porting C source code written for 32 to 64 bit


The C source codes that I am trying to port into 64 bit runs without any warning in the 32 bit environment. When I compile in 64 bit Linux environment with the compile gcc (Ubuntu 4.4.1-4ubuntu9) 4.4.1, it shows the following warning mostly:

warning: cast to pointer from integer of different size

The above warning were the most. I used uintptr_t type and most of those warnings were removed. I could change the type int /unsigned int into 64 bit favorable using uintptr_t. But how can I change the following type to make compatible to 64 bit:

typedef void*  POINTER;

I have changed the following code:

typedef unsigned int    ABC; 

into

typedef uintptr_t ABC

I got following warnings:

warning: passing argument 2 of ‘function’ from   incompatible pointer type
note: expected ‘ABC *’ but argument is of type ‘unsigned int *’

Moreover, after changing type def into uintptr_t which were earlier either int or unsigned int, I am encountering most of the warnings as follows:

warning: inlining failed in call to ‘abc_StringCopy’: call is unlikely and code size would grow

The function tptp_StringCopy is as follows:

static __inline__ char* abc_StringCopy(void)
{
  char *copy;
  copy = (char*)Malloc(yyleng+1);
  strcpy(copy, yytext);
  return copy;

How can I get rid of these warnings?


Solution

  • I'm not exactly clear on the situation, but it seems that You changed unsigned int to uintptr_t. The former is an unsigned int, the latter is an unsigned int pointer.

    In general, that's not a valid substitution to make.

    Also, you said the code "runs without warning on 32 bit" but compilation for 64-bit gives you warnings. But it really doesn't matter whether it runs without warning. Maybe you mean, it compiles without warnings. Is that true? The code you've modified, compiles for 32-bit without warning? That would be a surprise.