Date: Fri, 16 Jan 1998 00:49:36 -0600 (CST) From: Joel Ray Holveck <joelh@gnu.org> To: atrens@nortel.ca Cc: hackers@FreeBSD.ORG Subject: Re: sharable static arrays? Message-ID: <199801160649.AAA03638@detlev.UUCP> In-Reply-To: <199801160256.VAA18321@mescaline.gnu.org> (atrens@nortel.ca) References: <199801160256.VAA18321@mescaline.gnu.org>
next in thread | previous in thread | raw e-mail | index | archive | help
> Therefore, > const char foob[10] = "0123456789"; > will use 10 bytes ( all in text ) , and > char fooba[10] = "0123456789"; > will use 20 bytes ( ten in text, ten in data ). It's that simple. ;) I'm sorry, I must be misunderstanding something. I thought that in the latter case, the variable would be stored in data, period. If fooba[] was in BSS, I can see the need to have the text copy, but why if it's in the executable's data segment? How could I experiment with this? And, based on what you're saying, when does the initializer get copied? By crt0, in start? Somewhere I've got something in the back of my mind telling me that although the initializer for char*x will be stored in text, an initialized char x[10] will be stored entirely in data. If this is mistaken, please let me know. > Now, what's interesting is that > char foobar[10] = " "; > will *also* use 20 bytes - the compiler will pad the initializer with > zeroes. I am familiar with the phenomenon. I'll use it to set defaults for options: char tmp_path[PATH_MAX] = "/tmp"; Thanks for your patience, joelh -- Joel Ray Holveck - joelh@gnu.org - http://www.wp.com/piquan Fourth law of programming: Anything that can go wrong wi sendmail: segmentation violation - core dumped
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199801160649.AAA03638>