4 ms·
No, C does not define a single contiguous block of memory with consecutive addresses. It _does_ qualify that pointers are scalar types, but that does not imply
by groby_b 14y ago
No, C does not define a single contiguous block of memory with consecutive addresses. It _does_ qualify that pointers are scalar types, but that does not imply contiguity or consecutive addresses (with the exception of arrays)
There is no requirement in C that you be able to execute data.
You certainly could have a C implementation that bounds-checks strings and arrays. (See e.g. http://www.doc.ic.ac.uk/~phjk/BoundsChecking.html http://www.doc.ic.ac.uk/~phjk/BoundsChecking.html for a very old paper on how you might do that)
The "abstract machine" of C explicitly does _not_ make reference to the memory layout. (cf 5.1.2.3 of the spec)
It also makes no reference to the number of cores, and order of execution is not one at a time, but limited by sequence points.
That's the whole point of C - it is very loosely tied to actual hardware, and can accomodate a wide range of it, while still staying very close to actual realities.
Edit: Please don't take this as a "rah, rah, C is great" comment. I'm well aware of its shortcomings. I've spent the last 20+ years with it :)
- Locke1689 14y agoI would argue that C's problem is not that it's too strictly defined, but that it's too poorly defined. An in-depth look into all the cases of undefined behavior in C will show what I mean. You want to really understand C? Read this[0]. John really understands C. [0] http://blog.regehr.org/ http://blog.regehr.org/
- groby_b 14y agoCan't upvote this enough. Well, except that I'd replace "poorly" with "vaguely". "Implementation-defined behavior" is there for very good reasons in every single case it's there. Sidenote: With John's name, I'd be tempted on a daily basis to change the last two letters of my name to a single 'x' ;)
- georgeorwell 14y agoYou mean like this? $ whoami | sed 's/hr/xx/'
- eru 14y agoNo, he meant: $ whoami | sed 's/hr$/x/'
- georgeorwell 14y agoI think you mean: $ echo "$PARENT" | sed 's_r/x_r$/_' P.S. It's a bit hard to believe I misread that... thanks.
- eru 14y agoMy sed knowledge isn't very advance. What is your invocation supposed to do?
- dbaupp 14y agoYou can use any separator you want in an s/../../ expression, not just /, in this case the separator is _ (this technique allows you to use / without creating a "picket fence": s/r\/x/r$\//). So the regex just means replace "r/x" with "r$/".
- dbaupp 14y agoRandom tip: in Bash (at least), you can execute the previous command with some changes using ^..^..^, e.g. $ echo john regehr | sed s/hr/xx/ john regexx $ ^r/x^r$/^ echo john regehr | sed s/hr$/x/ john regex (The second last line is just bash printing the new command.)
- groby_b 14y agoMinor nit: She meant :)
- mikeash 14y agoI'd argue that there's a big distinction between C as described in the standard and C as actually used in real-world code, and the latter has much stricter semantics and is harder to work with. A C compiler that follows the standard but not the implied conventions won't do well. For example, take NULL. Even on a machine with no concept of NULL, you could easily emulate it by allocating a small block of memory and having the pointer to that block be designated as "NULL". This would be perfectly compliant with the standard, but it will break all of the code out there that assumes that NULL is all zero bits (e.g. that calloc or memset(0) produce pointers whose values contain NULL). Which is a lot of code. I'm sure that many other examples can be found.