Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: sizeof(x) / sizeof(x[0]) Date: Sun, 15 Jan 2017 12:55:58 -0800 Organization: None to speak of Lines: 28 Message-ID: References: <1420cd8f-e5cb-4a8f-93e6-d80a8b050650@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="a3056e3d6a9ef9101ceee550b325befe"; logging-data="4387"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/4Qa+oMCLGD21bIbxHQ60W" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:CxC9OxDPRShpqn+YqGBqDO7Lw1Q= sha1:/REP+h6HDwxLbycI1b86VStxkfg= Xref: csiph.com comp.lang.c:101882 Lőrinczy Zsigmond writes: > This snippet from gdb might be relevant: > > (gdb) print sizeof("ABCDEF") > $5 = 7 > > (gdb) print sizeof((char *)"ABCDEF") > $6 = 4 A snippet of output from a C program would be more relevant. gdb's evaluation of C expression isn't necessarily 100% reliable, though it's correct in this case. #include int main(void) { printf("%zu\n", sizeof "ABCDEF"); printf("%zu\n", sizeof ((char*)"ABCDEF")); } output: 7 8 -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"