|
I was wrong about the ordering thing! Standard lets you put the pointer argument and integral argument in either order as long as there's exactly one of each. Forming an invalid pointer is definetly undefined though. C0x 6.5.6 posted:When an expression that has integer type is added to or subtracted from a pointer, the result has the type of the pointer operand. And from the rationale doc since that's hard to parse C0x Rationale 6.5.6 1171 posted:Any pointer arithmetic that takes a pointer outside of the pointed-to object (apart from the one past exception) It gives a Motorola 56000 as an example of a real processor still in use where invalid addresses will fault in a footnote.
|
# ? Jul 26, 2017 08:15 |
|
|
# ? May 16, 2024 18:20 |
|
If you try to clean it up, remember that not all days have 24 hours.
|
# ? Jul 26, 2017 09:57 |
|
I wish language lawyers wouldn't pop out of the woodwork trying to one-up each other every time C is mentioned. Keep it in your pants please.
|
# ? Jul 26, 2017 12:19 |
comedyblissoption posted:If you try to clean it up, remember that not all days have 24 hours. Days have a defined capacity and there are no rules about 24 hour when overbooking
|
|
# ? Jul 26, 2017 12:30 |
|
Spatial posted:I wish language lawyers wouldn't pop out of the woodwork trying to one-up each other every time C is mentioned. Keep it in your pants please. I actually enjoy those arguments because I always learn something new.
|
# ? Jul 26, 2017 13:14 |
|
Spatial posted:I wish language lawyers wouldn't pop out of the woodwork trying to one-up each other every time C is mentioned. Keep it in your pants please. lol no Anyway, the restriction people keep quoting is specifically about pointer arithmetic, and it only prevents you from using pointer arithmetic to exceeds the bounds of an object (where those bounds include the one-past-the-end pointer), primarily as a way to allow the compiler to assume that subscripting into an array does not alias arbitrary other memory. It is not a general prohibition against forming or having a pointer that does not point at anything. It is of course undefined behavior to dereference a pointer that does not validly point to an object, outside of the specific exception for &*. The only general restriction on pointer values is that you cannot legally create a pointer that is less aligned than its pointee type; that is a rule that compilers are usually lax about until you actually use it to access the underlying memory. But if you cast 7 to a pointer type, that is legal (assuming the pointee type is byte-aligned); and if there happens to be an object of that type at address 7, then it is legal to dereference the resulting pointer; and since compilers generally cannot know statically every possible valid address of an object, it has to let you get away with it. (But null is different.)
|
# ? Jul 26, 2017 14:22 |
|
e. no wait, I misread you, you're more or less saying what I said.
|
# ? Jul 26, 2017 15:38 |
|
Spatial posted:I wish language lawyers wouldn't pop out of the woodwork trying to one-up each other every time C is mentioned. Keep it in your pants please.
|
# ? Jul 26, 2017 17:01 |
|
Spatial posted:I wish language lawyers wouldn't pop out of the woodwork trying to one-up each other every time C is mentioned. Keep it in your pants please. C is the only language with which I can tolerate these talks. It's such a slow moving language with so many weird corners that will *never* be fixed.
|
# ? Jul 26, 2017 18:17 |
|
Jabor posted:For example, merely computing the value can cause an overflow trap if it's outside the allowed range (while if the newly-computed pointer is inside the allowed range, the compiler must ensure that it doesn't overflow). rjmccall posted:compilers generally cannot know statically every possible valid address of an object, it has to let you get away with it. Also it's fun that I can't generate pointers outside objects, but the compiler's free to make them and leave them in memory willy nilly.
|
# ? Jul 26, 2017 18:53 |
|
This code had lots of spots where unrecoverable errors are caught and logged, then the methods return unexpected nulls, to blow up elsewhere.
|
# ? Jul 26, 2017 20:33 |
|
JawnV6 posted:Now I'm confused, why could an index into an object not overflow? That seems like the runtime's job to allocate things, if it puts an object right at the edge of memory or going over, the compiler can't know that indexing the last element would overflow. One past the last element, but yes, the runtime should generally not allocate things all the way up to the end of the address space. Typically this is not a problem because that part of the address space is either not allocable or allocated for something that's normally addressed. This is required by two rules: one, the end address must compare greater than all the addresses in an arary, and two, it's not allowed to compare equal to null (I think). Of course, null doesn't have to be the zero address, and you don't have to use normal integer comparison to compare pointers, but you'd still have a boundary condition somewhere. JawnV6 posted:Also it's fun that I can't generate pointers outside objects, but the compiler's free to make them and leave them in memory willy nilly. Yep! We do it just to mock your pathetic inability to violate the norms of the language we've trapped you within. rjmccall fucked around with this message at 23:26 on Jul 26, 2017 |
# ? Jul 26, 2017 23:23 |
|
rjmccall posted:(But null is different.)
|
# ? Jul 26, 2017 23:28 |
|
idiotmeat posted:Except on OS390 where NULL can be dereferenced. By which you mean it's mapped? A lot of operating systems let you map the zero page; it's not a good idea, but they let you do it. It's still undefined behavior even if it doesn't trap. We get requests on Clang sporadically to support dereferencing the zero address for some embedded / boot-loader project where zero is actually a significant address (that they often need to address by literal value, no less) and I'm always like, how much feature work exactly would you like us to do to simplify this task for you, and would you actually use that feature if we did it? rjmccall fucked around with this message at 01:12 on Jul 27, 2017 |
# ? Jul 27, 2017 01:09 |
|
Not mapped - it can always be dereferenced.
|
# ? Jul 27, 2017 01:53 |
|
What does it dereference? 0? Undefined behavior?
|
# ? Jul 27, 2017 01:55 |
|
john donne posted:What does it dereference? 0? Undefined behavior? There is some OS related structure which is always located at virtual address 0.
|
# ? Jul 27, 2017 02:10 |
|
rjmccall posted:By which you mean it's mapped? A lot of operating systems let you map the zero page; it's not a good idea, but they let you do it. It's still undefined behavior even if it doesn't trap. My totally controversial opinion is that the CPU should hardware fault if you attempt to access the first pointer-sized bytes of memory even on embedded hardware without an MMU because seriously... gently caress that. On anything 386-class or newer it should be the entire first page. Anyone who thinks otherwise is wrong and I condemn to hell CPU and system designers that require use of address zero.
|
# ? Jul 27, 2017 05:05 |
|
rjmccall posted:lol no I was curious and found this in the section for conversions: C0x 6.3.2.3 posted:An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant. A compiler isn't allowed to refuse to compile char* a = (char*)5; and is supposed to document what it does, but doesn't have to do any particular thing.
|
# ? Jul 27, 2017 05:31 |
|
Again, unless the compiler knows for certain that there is not a valid object at address 5 — which in general it cannot — it has no choice but to emit the accesses as given. In the absence of undefined behavior, the compiler must implement the abstract machine. The null pointer is a special case precisely because the compiler is allowed to assume that there is never a valid object at that address. Now, if LLVM sees that you've constructed a constant address like that, it will assume that that pointer does not alias any other sort of declared memory. That is, it assumes that (char*) 0xf00 is not a correct guess of the address of const char *myGlobalString; or int myLocalCount;, even though, yes, it is possible to write a linker script that will force a variable to be loaded at a specific address. Our request is that, if you do have some memory-mapped use case where that's important, you should please use either constant addresses or that kind of linker script but don't awkwardly combine them.
|
# ? Jul 27, 2017 05:49 |
|
Spatial posted:I wish language lawyers wouldn't pop out of the woodwork trying to one-up each other every time C is mentioned. Keep it in your pants please. language lawyers are the only reason your certified retarded c code even compiles, much less runs efficiently. how dare you, sir, how dare you.
|
# ? Jul 27, 2017 05:54 |
|
LLVM = Language Lawyer Virtual Machine
|
# ? Jul 27, 2017 06:05 |
|
Better call/cc Saul
|
# ? Jul 27, 2017 10:14 |
|
Bytecode Legal
|
# ? Jul 27, 2017 13:12 |
|
JewKiller 3000 posted:language lawyers are the only reason your certified retarded c code even compiles, much less runs efficiently. how dare you, sir, how dare you. Where can I go to get my C code certified as retarded?
|
# ? Jul 27, 2017 13:35 |
|
Law & Order of operations
|
# ? Jul 27, 2017 13:59 |
|
code:
|
# ? Jul 27, 2017 15:20 |
|
JawnV6 posted:Also it's fun that I can't generate pointers outside objects, but the compiler's free to make them and leave them in memory willy nilly. See also go generics.
|
# ? Jul 27, 2017 15:40 |
|
ChaosArgate posted:
Photons.
|
# ? Jul 27, 2017 15:56 |
|
idiotmeat posted:Photons. Baryons.
|
# ? Jul 27, 2017 16:27 |
|
Factor Mystic posted:Law & Order of operations In the software system, the people are represented by two separate, yet equally important, groups: the coders, who write programs; and the posters, who prosecute the coders for their language crimes.
|
# ? Jul 27, 2017 16:47 |
|
Doc Hawkins posted:In the software system, the people are represented by two separate, yet equally important, groups: the coders, who write programs; and the posters, who prosecute the coders for their language crimes. These are their user stories.
|
# ? Jul 28, 2017 00:42 |
|
Fergus Mac Roich posted:Where can I go to get my C code certified as retarded? GCC
|
# ? Jul 28, 2017 00:56 |
|
DaTroof posted:These are their user stories. UXXX Design
|
# ? Jul 28, 2017 01:15 |
|
Today I broke a jasmine test that looked like this:code:
|
# ? Jul 28, 2017 02:34 |
|
Rubellavator posted:Today I broke a jasmine test that looked like this: How did that ever pass?
|
# ? Jul 28, 2017 11:16 |
|
Doom Mathematic posted:How did that ever pass? Since it’s JavaScript, I’m not ruling out the possibility that it compared functions using toString and they happened to match.
|
# ? Jul 28, 2017 11:41 |
|
The unreasonably optimistic alternative is that equality between function objects compares their pointers, and this particular JS engine is smart enough to de-duplicate a redundant function definition.
|
# ? Jul 28, 2017 12:43 |
|
Or it silently ignored fields it didn't know how to compare.
|
# ? Jul 28, 2017 14:53 |
|
|
# ? May 16, 2024 18:20 |
|
Whoops. It was pretty late yesterday when I came across that and I didn't play with it very much. The actual call was toEqualData, which only compares the value of the properties, but had the entire object copied from the source including the functions. Still a pretty silly test. The value of the properties aren't derived, so I guess it's just a test for whether someone accidentally changed a property.
|
# ? Jul 28, 2017 15:32 |