Empty structures have sizeof(1) in C++ now ?

From: Poul-Henning Kamp <phk_at_phk.freebsd.dk>
Date: Thu, 20 Feb 2025 09:40:54 UTC
Is this a bug ?


	critter phk> cat /tmp/_.c

	#include <stdio.h>
	struct foo {
	};

	int
	main(int argc, char **argv)
	{
		struct foo bar;
		printf("%jd %jd\n", sizeof(struct foo), sizeof(bar));
		return (0);
	}
	critter phk> cc -o /tmp/a.out /tmp/_.c
	critter phk> /tmp/a.out
	0 0
	critter phk> c++ -o /tmp/a.out /tmp/_.c
	c++: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
	critter phk> /tmp/a.out
	1 1

-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.