[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

wtf is n1570?

pete

6/29/2011 3:14:00 PM

In another forum I'm arguing against an outlandish claim: that
modifying a variable marked as const in a C source file generates a
run-time error because it is (as is claimed) undefined behavior.

The other guy's reference is n1570, ( http://www.open-std.org/jtc1/sc22/wg14/www/docs...
) section 6.7.3.

That section does indeed seem to support his argument. Horrifying!

So I ask you, sisters and brothers, what IS this n1570? And does it
have any force of law?

Thanks!

1 Answer

Eric Sosman

6/30/2011 1:24:00 AM

0

On 6/29/2011 11:13 AM, pete wrote:
> In another forum I'm arguing against an outlandish claim: that
> modifying a variable marked as const in a C source file generates a
> run-time error because it is (as is claimed) undefined behavior.

It is in fact undefined behavior. It does not necessarily produce
a run-time error, though: "undefined" means "not defined," so anything
at all may (in principle) occur. You might get a crash, you might see
the sudden inversion of every sign bit in the program, you might see
something you sort of expected. It used to be said that UB could make
demons fly out of your nose; from the Standard's point of view the
nasal demons are entirely plausible, although the engineering challenges
are somewhat daunting.

> The other guy's reference is n1570, ( http://www.open-std.org/jtc1/sc22/wg14/www/docs...
> ) section 6.7.3.
>
> That section does indeed seem to support his argument. Horrifying!
>
> So I ask you, sisters and brothers, what IS this n1570? And does it
> have any force of law?

There's a really informative web site that has a lot of information
about this and many other topics. Can't recall the name, exactly --
goggle.com? giggle.com? When I'm not so busy, I'll google it.

As for "force of law," well, no. IANAL, but to the best of my
knowledge you cannot be fined, jailed, or summarily executed for
disbelieving a draft International Standard, nor even the adopted
International Standards that contain equivalent language. I suppose
that if you contracted with someone to do "C programming" and your
work product did not follow "accepted professional norms" you might
be open to a civil lawsuit, but I don't think it rises to the level
of an actual felony. So, yeah: In my non-lawyerly opinion, trying
to alter a const-qualified object is every bit as legal as trying to
dereference a NULL pointer. Go for it!

--
Eric Sosman
esosman@ieee-dot-org.invalid