[Cryptography] bounded pointers in C

Jerry Leichter leichter at lrw.com
Sat Apr 19 23:48:22 EDT 2014


On Apr 19, 2014, at 10:49 PM, Nemo <nemo at self-evident.org> wrote:
> Oh, I see... You meant "literal", not "constant".
Yes, thanks - I should have used the right term of art.  I hadn't slipped into "standardese" mode.

> You might be interested in C++11's user-defined literals, which let you
> define "_safe" as a literal suffix so that you can write:
> 
>  s = 12_safe * s;
> 
> (Live example again: http://goo.gl/gvZrFt)
> 
> I concede the equivalent is messier in C++03. Although not by much; is
> writing "SafeInt(12)" really so hard?
Nothing, other than that (a) it's rather verbose and makes for ugly expressions; (b) as I've said repeatedly, it all works fine *if you've written the code to work with the library*.  What you can't do is just add the library, change some type declarations, and suddenly have existing code "just work" but with a new datatype.

It's always been a goal of C++ to allow user-defined types to look as if they were completely built into the language.  (You can disagree with the goal, in which case none of this matters to you, but that was and is a goal.)  C++ has always been remarkably good about that - much better than any other language I know of.  Yes, C++11 has - with things like literal suffixes (I forgot about those - I haven't actually had the chance to *program* in C++11, so haven't internalized much of the new stuff) and the new initializer formats - gotten even better.  But it's still not possible to provide *exactly* the detailed semantics of the built-in types - semantics inherited from C, mind you; that C++ been defined from the ground up with semantics appropriate for the "user can write classes that look completely built in" goal, the story would likely have been different.  Mind you, it's not necessarily a failing of C++ that you can't do this - few ever have the need, and providing it for them would mean wading into the huge morass of details that is the automatic type coercions and conversions and adjusting everything to fit together.

Still, every one in a while, it would be really nice to be able to do such a thing....
                                                        -- Jerry



More information about the cryptography mailing list