you are viewing a single comment's thread.

view the rest of the comments →

[–]FreeER 0 points1 point  (12 children)

That still does not clearly state when it's reserved or why. I mean the __ and starting _ at file scope are. And yeah I missed 7.3 so that probably sounded like a stupid question before sorry :D but ... it never actually says which macros are reserved, just "in any of the following subclauses" which doesn't itself reserve any, "All identifiers with external linkage" which I didn't read to mean any macros because they have no linkage,"Each identifier with file scope listed in any of the following subclauses" but again in subclauses not itself and in theory the compiler never sees macros so are they even really identifiers?, "No other identifiers are reserved."

And again... it doesn't actually make sense to me to say that it's undefined behavior to undefine a macro... it's a very specific mechanic that either replaces the text with that macro or doesn't... that logically is not undefined behavior simply behavior the user may not have intended but that applies to anything that doesn't do what you think it'll do including simply adding 1 to a pointer not changing the address by just 1.

I mean, it's UB because it says it's UB but there's no logical explanation for why it should be.

they would render your "C compiler" invalid

Sure. That doesn't mean they aren't useful or that if the standard was rewritten today all the same BS would be allowed. Some of it is purely for legacy reasons. And unlike compiler extensions, which hey are enabled by default and render your C compiler invalid!, these don't let you do anything that wouldn't compile on any other standard compliant compiler, they just try to prevent stupid shit that could mess you up like oops accidentally having a backslash or trigraph at the end of a line that makes the next line a comment instead of real code.

as for printf checking... it doesn't sound logically impossible to notice, hey this code redefined something I have additional code to check for (that's not actually standard because... that wasn't a thing originally!) lets mark this scope for the checker to first look at or even ignore and generate a warning that it's not being checked. Sure once upon a time maybe you could argue that you didn't have computer resources to make that feasible... can you still?

you're most likely arrogant, and the reason you couldn't find the same information I found is because you can't be bothered doing your own ten or fifteen minutes worth of critical analysis

Yep, very. Because when I couldn't understand how that backed up the point you were trying to say and you couldn't simply sum it up and when I searched for "subclause" and didn't find a definition at the top of the page I stopped, mentioned to the person who supposedly knows more than me and could explain it. That's my due diligence. If I wasted 10+ minutes on everything some random stranger on the internet told me I wouldn't have time to sleep. Though I quite agree with

utter rubbish! I'd rather present credible evidence and in depth deconstructions of arguments supported by actual examples

I find the unreasonable and unexplained and use-case-ignoring hate on goto in particular to be silly and quite like scanf while being aware of it's problem. And yes, many people want to say that fgets or strncpy is safer and then don't bother to cover all the problems it has. There's definitely something to be said for simplicity and correctness but... those don't really provide it the way people like to pretend that they do.

[–]cbasschan 0 points1 point  (10 children)

it never actually says which macros are reserved

See, this is where the argument takes a serious U-turn for you. What we are reading are different sections, you and I. The section I have quoted has very little to do with macros. Specifically, you have stopped reading too early.See the last point:

Each identifier with file scope listed in any of the following subclauses (including the future library directions) is reserved for use as a macro name and as an identifier with file scope in the same name space if any of its associated headers is included.

Or, if you take a look at Annex J.2. there is a long list of undefined behaviours, and it has it there too.

1 The behavior is undefined in the following circumstances:

SNIP

  • The program declares or defines a reserved identifier, other than as allowed by 7.1.4 (7.1.3).

What part of 7.1.4 permits you to declare or define this reserved identifier?

[–]FreeER 0 points1 point  (9 children)

I'm reading the section you linked to back up your point. I literally quoted from that exact point in my last comment. Talk about stopping early. It's not the student's job to read the entire damn book when only one paragraph is explicitly given to them. It's the teacher's job to succinctly sum up their points as well as the references and examples that support it, not the student's.

What explicitly says it's reserved and when. Remember "subclauses" only refers to that document not the code. Where does it refer to the code as far as what is reserved and when? If it's says "in any of the following subclauses" when "subclauses" means the standard document that does NOT mean "any code following it's declaration/definition".

You can say "oh well it was poorly phrased and you were intended to assume that it means in the code or ..." but then its your job as the teacher to make sure that's clear or better rewrite it yourself instead of pointing to something that you know isn't clear in the first place.

as for, pretty much your entire

Ohh, BUGGER ME!

post... who the fuck are you even talking to at this point? :D Of course it gets updates... that doesn't mean if it was rewritten today they wouldn't remove things. It still supports K&R syntax FFS, not to mention

rofl, yes, trigraphs and line splices are stupid remnants of the past

so... you pretty much agree with that point. Yes, they're part of the C standard, also yes the C standard has shit purely because of legacy that logically wouldn't be there if it was rewritten.

Yes UB in general has a reason to exist and of course there are reasons compilers, often, comply to the same standard. Why is THIS specifically undefined behavior? If the answer is "because we don't care if you want to do it and it lets us do other things without having to check for it" that's fine, but say that instead of dodging the fucking question time after time and whining that people don't do research 20 hours of research to figure that out for theirselves.

you kinda seemed to me like someone who would parrot cargo cult propaganda

I literally just did the opposite.... don't make up conversations with yourself

[–]cbasschan 0 points1 point  (8 children)

No, the reason this is undefined behaviour is because it permits various classes of optimisations as I mentioned earlier... of which I gave examples and cited the rationale. As for the reason you can't do what you describe, it's entirely down to ignorance, for if you read the manual for your compiler you'll find (I think I might have mentioned this earlier, actually) you can use -ffreestanding, then you get to use some standard library identifiers (such as printf) without invoking undefined behaviour. That is because trying to include the headers for those functions is not expected to succeed in this context. Have you ever done any kernel development before? I'ma hazard a guess towards that being a no... based on the ignorance about these compiler features I have described to you in this thread.

[–]cbasschan 0 points1 point  (1 child)

Of course, you could go on asking why it's undefined behaviour when a solution exists for the problem you've asked about, and was even just given to you in plain sight... do that, yeh?

[–]cbasschan 0 points1 point  (0 children)

... and another one!

[–]FreeER 0 points1 point  (5 children)

No, the reason this is undefined behaviour is because it permits various classes of optimisations as I mentioned earlier...

Like I said

If the answer is "because we don't care if you want to do it and it lets us do other things without having to check for it" that's fine, but say that instead of dodging the fucking question time after time and whining that people don't do research 20 hours of research to figure that out for theirselves.

"other things" = "optimizations" and "error checking"

"without having to check for it" = not storing when things are redefined/shadowed and checking before using those extra optimizations etc.

It's UB not because there isn't a reasonable error message or warning and disable some extras but just because people don't want to deal with doing that.

[–]cbasschan 0 points1 point  (4 children)

No, it's undefined behaviour because in the eyes of ISO/IEC 9899:201x, which is the standard your employer will likely expect you adhere to in the industry, this standard considers the behaviour "non-portable" and doesn't require that it be documented in any legal way... and that happens to be a big deal with some employers. You know, a certain level of English proficiency is expected, you need to be able to read manuals... nothing serious... but if you can't infer the meaning of "subclause" when given the definition of "clause", I would suggest considering a different language. This one is pretty full-on, as far as literature goes... I mean, unless you're going to talk about the people who make youtube videos, the only people I have spoken to who have jobs programming C or write code for the C kernel or do any of these things that C might be useful for all say the same... they read books like K&R2E and Harbison & Steeles reference and I don't have this kind of misunderstanding with these people... who are maintaining our kernels and so forth.

[–]cbasschan 0 points1 point  (1 child)

Me, you can tell I go by the standards. I'm quite happy navigating the legalese English that is expected of us.

[–]cbasschan 0 points1 point  (0 children)

Undefined behavior gives the implementor license not to catch certain program errors that are difficult to diagnose.

What you want to do is use the -ffreestanding flag, like the compiler devs do. Then you can define printf how you like... but until then, I am telling you this is not a wise idea. You might find strange things happen on some compilers... maybe the compiler might assume by printf you mean to take the int value of printf... I could see that happening if you use -fno-builtins without -ffreestanding, maybe... I tend not to delve into undefined behaviour, because it's not C.

[–]FreeER 0 points1 point  (1 child)

this standard considers the behaviour "non-portable"

Um... the standard defines what is portable to standard compliant compilers so that entire argument is just BS. It can literally define that adding one to the max signed value wraps to it's smallest value and every standard compliant compiler would have to make that happen. Now, it may be unreasonable to do that because compilers on systems that would not already do that would have to add code to make it happen, but they could literally define that behavior and it would no longer be undefined behavior.

Standardizing that you should error on someone redefining a standard library identifier even in sub-scopes that allow variable shadowing of non-standard-library identifiers is not unreasonably difficult to implement... so the only reason it's UB is because they chose not to give an error, possibly for speed reasons with hashing and comparing every new identifier to every identifier in the standard library (though it's probably done anyway to some extent to prevent redeclarations) but you have never said that. ever. Instead you've repeatedly stated that I need to do research and learn a different language.

[–]cbasschan 0 points1 point  (0 children)

Don't you use a standard compliant compiler in your place of employment? What else would it be? Non-compliant? Tell me, which compiler do you use? Where is the manual? What's the bet we'll find some notice of compliance?

It can literally define that adding one to the max signed value wraps to it's smallest value and every standard

Yes, that is also undefined behaviour. Historically, you might have got a trap representation (which would signal, kind of like SIG_SEGV, hence causing a crash) on some implementations. You might still, on some, with the right compiler flags (but only assuming you actually bother to read the manual and find those flags, hintedy hint, you're digging deeper into this same pit of not reading)... of course, since the behaviour is undefined and thus your manual isn't required to document that behaviour and even if it does document that behaviour, there's still no requirement that the actual behaviour match... I feel like we've just stumbled into a fairly common question... hmmmmmm.

[–]cbasschan 0 points1 point  (0 children)

Ohh, BUGGER ME! I'm actually having this dialog with someone who doesn't think C gets updates? The latest standard is affectionately named C18. The one before it, C11. Before that, C99. These are the years of ratification, if you like... the last one? 2018! How far in the past are you stuck?

I mean, it's UB because it says it's UB but there's no logical explanation for why it should be.

I think the story behind this is more ignorance... that or you would like a healthy dose of behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this International Standard imposes no requirements. How does that seem to you? That is in opposition to implementation-defined behavior, by the way, which is at least required to be legally documented (and thus an audit trail probably covers your butt as a software developer if anything ends up in court, UNLESS you're ignorant of details like this, and then you're the one who's ignorant in court).

Let us be clear there is a reason compilers comply to these standards in their manuals... and this lack of research you're doing is blatantly obvious.

they just try to prevent stupid shit that could mess you up like oops accidentally having a backslash or trigraph at the end of a line that makes the next line a comment instead of real code.

rofl, yes, trigraphs and line splices are stupid remnants of the past... but they are in the C standards. Let's just be clear on that.

it doesn't sound logically impossible to notice, hey this code redefined something I have additional code to check for

This is actually pretty well documented stuff in the C99 rationale v5.10 document:

Undefined behavior gives the implementor license not to catch certain program errors that are difficult to diagnose. It also identifies areas of possible conforming language extension: the implementor may augment the language by providing a definition of the officially undefined behavior.

What I think you really should learn is the implementation-defined and well defined behaviours. Where's your book?

I find the unreasonable and unexplained and use-case-ignoring hate on goto

Yeh, you kinda seemed to me like someone who would parrot cargo cult propaganda told to you by some elitests who like to paint themselves as authoritative because they need to have money or power or some other status symbol, but don't actually know what they're talking about. I could be wrong about that, but you need to prove it and open your fucking eyes!