c: define constants
Hi,
i would to declare the return values as constants. However, the problem is that i have to return pointers to the constants. How do i do that? Adding the "&" operator on the return values causes warnings, too. And "#define *IS_PROC_ID 1" and similar don't seem to be solutions. Ideas? Thanks, Kostas Code:
#define IS_PROC_ID 1 Code:
res.c: In function ‘selector’: |
Umm .. you can't do that
Also I can't understand why you're returning a pointer in that example .. but perhaps that is just for example's sake Theese defines simply get substitutet in the code .. so when you write Code:
return IS_PROC_ID; Code:
return 1; Code:
int * x() Also I hope that the code you posted is just an example .. since it makes no sense returning a pointer in there |
Code:
int * p = new int(IS_PROC_ID); Code:
#define IS_PROC_ID 1 |
Hi,
I would just erase the little astericks at the begginning of the function, and just return an int value. It would be much much happier (as mentioned before). Cheers! |
Thanks everybody. I must use the specific method declaration.
introuble: this works OK. |
Quote:
Code:
if ((d->d_type==DT_DIR) && (is_number(dir_name)==1)) as cupubboy said, the #define'd name is getting replaced with the value. so return (int *)IS_PROC_ID; is the same as saying return (int *)1; which does not segfault there, or give warnings.. but try to print the value of the returned pointer. printf("%d", *(selector(...))); segfault because you are trying to access memory at address 1. cant do it. and if you are going to use the actual value of the ptr (which would work here) why not just use an int value and have the code be readable. |
All times are GMT -5. The time now is 04:49 PM. |