Return struct from function

Possible duplicate:
Returning the structure containing the array

I have a simple code:

struct s { char str[128]; }; struct s foo() { struct ss = { "some string" }; return s; } int main() { printf("%s\n", foo().str); return 0; } 

but it gives a warning:

warning: format '% s expects an argument of type char *, but argument 2 is of type' char [128] [-Wformat]

if i change the main function as

 int main() { struct ss = foo(); printf("%s\n", s.str); return 0; } 

everything is good. so what is the problem in the first code? thanks.

ps. im using gcc-4.7.0

SFC. note, the problem only occurs with the C compiler, with C ++ everything is fine

+6
source share

Source: https://habr.com/ru/post/916741/


All Articles