LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to return empty char * ? (https://www.linuxquestions.org/questions/programming-9/how-to-return-empty-char-%2A-750700/)

cpthk 08-28-2009 05:41 PM

well, the code was not written by me. The code was from windows, it compiled fine and running fine so far. I am switching the library to linux to run. I guess it might be changed after returned, so I don't want to change to constant.

orgcandman 08-28-2009 11:17 PM

Quote:

Originally Posted by fantas (Post 3660868)
So what's the difference ?

As an exorcise for the reader, I will let you evaluate how "\0" != NULL, and what it means for string manipulation functions (and what the value of "\0" versus NULL would be).


Quote:

Of course not, without enabling all warnings.
Code:

[12:23:02][aconole@ssh:~]
$ cat test.c
#include <stdio.h>
#include <string.h>

char *foo()
{
    return "\0";
}

int main()
{
    char *f = foo();

    *f = 'a';

    return 0;
}
[12:23:11][aconole@ssh:~]
$ gcc -Wall -o t test.c
[12:23:17][aconole@ssh:~]
$ ./t
Segmentation fault
[12:23:19][aconole@ssh:~]
$

Not trying to troll here, but you might want to check before you make a claim.


All times are GMT -5. The time now is 04:58 PM.