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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -