Is it possible to determine whether a string can not be written on the side it had been passed to as a char * string
?
my code:
#include <stdio.h>
typedef enum string_type
{ READ_ONLY, READ_WRITE }
String_type;
String_type isvalid(char *s);
void test(char *s){
if(isvalid(s))
printf("OK\n");
else
printf("NG\n");
}
int main(void){
char data_str[] = "data_str";
test("data_str");// fails
test(data_str);// works
return 0;
}
String_type isvalid(char *s){
//Can it be determined by this?
//I don't think this is a portable way.
return (void *)s > (void *)main ? READ_ONLY : READ_WRITE;
}