Linux SPARSE checker discussions
 help / color / mirror / Atom feed
* declarations after a case statement
@ 2026-06-04 13:40 Dan Carpenter
  2026-06-04 13:48 ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2026-06-04 13:40 UTC (permalink / raw)
  To: linux-sparse

Sparse doesn't let you declare a variable immediately after a case
statement but that's something we do in the kernel these days.  The
"b" declaration is fine, but "c" generates a warning.

regards,
dan carpenter

$ ./sparse test.c
test.c:10:17: error: typename in expression
test.c:10:21: error: Expected ; at end of statement
test.c:10:21: error: got c
test.c:10:17: error: undefined identifier 'int'
$

#include <stdio.h>

void func(int a)
{
	switch (a) {
	case 1:
		printf("hello\n");
		int b;
	case 2:
		int c;
	}
}


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

end of thread, other threads:[~2026-06-05 12:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-04 13:40 declarations after a case statement Dan Carpenter
2026-06-04 13:48 ` Dan Carpenter
2026-06-04 14:21   ` Derek M Jones
2026-06-05  5:50     ` Dan Carpenter
2026-06-05 10:43       ` Derek M Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox