現代のCで返り値に型のある関数でreturn;したらどうなるんだろう!!
Conversation
Notices
-
Embed this notice
zunda (zundan@mastodon.zunda.ninja)'s status on Saturday, 23-Nov-2024 11:02:30 JST zunda -
Embed this notice
zunda (zundan@mastodon.zunda.ninja)'s status on Saturday, 23-Nov-2024 11:03:04 JST zunda UBだ♪
$ cat return.c
#include <stdlib.h>
#include <stdio.h>int function(void){
return;
}int main(void)
{
printf("%d\n", function());
return 0;
}
$ gcc return.c && ./a.out && ./a.out && ./a.out
return.c: In function ‘function’:
return.c:5:3: warning: ‘return’ with no value, in function returning non-void
5 | return;
| ^~~~~~
return.c:4:5: note: declared here
4 | int function(void){
| ^~~~~~~~
-198725291
1404641621
1343713621
-
Embed this notice