public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Problems in array access
@ 2021-08-31  8:10 Utkarsh Singh
  2021-08-31  8:28 ` Jonathan Wakely
  0 siblings, 1 reply; 5+ messages in thread
From: Utkarsh Singh @ 2021-08-31  8:10 UTC (permalink / raw)
  To: gcc; +Cc: Aakarsh MJ

Hello GCC mailing list,

In one of my friend's C programming class, they asked him a question on
the topic of array bounds based on the follwing code snippet:

#include <stdio.h>

int main(void)
{
	char str[] = {'G' , 'C' , 'C' };
	str[3] = '\0' ; /* Isn't this invalid? */
	printf("%s\n", str);
}

In an ideal case, str[3] should be a case of out-of-bound array access.
But when compiling the above with -Wall option flag GCC shows no
warning.  So, am I missing something?

Thank you,
Utkarsh Singh

-- 
Utkarsh Singh
http://utkarshsingh.xyz

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-09-01  2:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-31  8:10 Problems in array access Utkarsh Singh
2021-08-31  8:28 ` Jonathan Wakely
2021-08-31  8:39   ` Utkarsh Singh
2021-08-31 15:08     ` Martin Sebor
2021-09-01  2:31       ` Utkarsh Singh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).