c - warning: return makes pointer from integer without a cast but returns integer as desired -


i'm trying find out proper way return integer void * function call within c.

ie ..

#include <stdio.h>  void *myfunction() {  int x = 5;  return x; }  int main() {   printf("%d\n", myfunction());   return 0; } 

but keep getting:

warning: return makes pointer integer without cast

is there cast need make work? seems return x without problem, real myfunction returns pointers structs , character strings work expected.

it's not obvious you're trying accomplish here, i'll assume you're trying pointer arithmetic x, , x integer arithmetic void pointer on return. without getting why or doesn't make sense, can eliminate warning explicitly casting x void pointer.

void *myfunction() {  int x = 5;  return (void *)x; } 

this raise warning, depending on how system implements pointers. may need use long instead of int.

void *myfunction() {  long x = 5;  return (void *)x; } 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -