Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Feb 2025 09:40:54 +0000
From:      Poul-Henning Kamp <phk@phk.freebsd.dk>
To:        current@freebsd.org
Subject:   Empty structures have sizeof(1) in C++ now ?
Message-ID:  <202502200940.51K9eswS003142@critter.freebsd.dk>

index | next in thread | raw e-mail

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.


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202502200940.51K9eswS003142>