Porting C source code written for 32 - 64 bits

C source codes that I am trying to execute in 64-bit without warning in a 32-bit environment. When I compile in a 64bit Linux environment with the gcc compiler (Ubuntu 4.4.1-4ubuntu9) 4.4.1, it shows the following warning basically:

warning: cast to pointer from integer of different size

The above warning was the biggest. I used the uintptr_t type , and most of these warnings have been removed. I can change the int / unsigned int type to 64 bit using uintptr_t . But how can I change the following type for compatibility with 64-bit:

typedef void*  POINTER;

I changed the following code:

typedef unsigned int    ABC; 

at

typedef uintptr_t ABC

I got the following warnings:

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

, def uintptr_t, int unsigned int, :

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

tptp_StringCopy :

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

?

+3
4

, , unsigned int uintptr_t. - int, - int-.

, .

, , " 32- ", 64- . , . , , . ? , , 32- ? .

-1

unsigned int uintptr_t 64- . int unsigned int 32- 64- , uintptr_t 64- . , uintptr_t, , , , . , uintptr_t 32- 32- , 64- 64- .

, typedef 64- NAT* 64- 64- , unsigned int* - 64- 32- .

clause_ComputeSplitFieldAddress unsigned int*.

+2

, , - , 32- - . 32- , 64- : 64-. , 32 64 .

NAT, ? ( 32- 32- ), void *, uintptr_t.

+1

POINTER typedef; void - void 32-, 64- ( 32- 64- ). POINTER , -, .

clause_ComputeSplitFieldAddress, , "unsigned int", "NAT *"; , , - , int NAT.

tptp_StringCopy, , strdup() - , , , .

, List_Cons(), .

, 32- 64- , , punning . , uintptr_t (, , <inttypes.h>). , <inttypes.h>, typedef. ,

PRIXPTR

uintptr_t:

printf("0x%08" PRIXPTR "\n", ptr_as_int);

; .

The compiler has the right to warn you if it wants the code not to be embedded. There is not much that you can do about this, except to request an attachment of functions that cannot be inlined.

+1
source

Source: https://habr.com/ru/post/1735739/


All Articles