[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: gEDA-user: C question



On Sat, Mar 03, 2007 at 03:23:22AM +0000, carzrgr8@xxxxxxxxxxxxx wrote:
> Look at the following:1) int bob[5] = {0x1, 0x2];2) int const bob[2] = {0x1, 0x2};3) static int const bob[2] = {0x1, 0x2};1  creates an initialized array in ram.2 creates a read-only array - presumably in ROMWhat does 3 do?  I think 3 compiles to a read-only area of ram.  Am I correct?gene

static vs nothing (non-static, default) has to do with linking.  A static
variable is not "global" and cannot be accessed from other modules (files,
basically) when compiling.  It's basically hiding data and avoiding
namespace polution.

const vs nothing (non-const, default) determines whether you can modify
the data.  The compiler may put the data somewhere different than it
would put other initialized data, or it may not.  Where you put const
matters, because in one declaration different things might be protected.
For example,

	const char *p;	/* p points to 'const chars', an immutable string */
	char const *p;  /* the pointer p can't change, but the chars can */
	const char const *p; /* neither p nor the chars it points at change */

So without looking it up, I'm not sure what your 'int const bob[]' means,
but you probably mean 'const int bob[]', the ints in bob don't change.

-- 
Ben Jackson AD7GD
<ben@xxxxxxx>
http://www.ben.com/


_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user