I think we should name this feature.
in C: assertive prototype
in C++: assertive declaration
> [snip]
> > The idea:
[snip]
> Hum. While it might be possible to put this in, it could not
> be checked at compile time, at least not in general. You can't
> always pre-compute the call values of functions. You can't even
> pre-compute whether a function will actually be called.
> So, these checks might be created, but they could only actually
> be tested against at run time. The same is true for checking
> return values.
You are correct. It *is* meant for runtime. It has to be. We are going
to assert against actual parameters.
> > Advantages:
> > 1. Clear communication to the person who links her code
>
> Well, maybe. It does not necessarily happen that it's any
> clearer to the client coder. I've always found that a good
> set of documentation is worth a lot.
>
> What happens if the user tweaks the .h file to change the limit?
> Or even removes the limit, expecting to be able to get a log
> function to take negative values. Might be undefined behaviour.
It would not change the behavior because the function / method was
compiled with original set of values. However, this may throw things
out of sync. Does not the same happen in case of header files now?
> > 2. Robust programming
> > 3. Definitions (function bodies) become more readable
> > 4. Assertions become more maintainable
>
> Possibly. Though it seems like it's just moving testing from
> inside the code to insde the function call. It may make it a
> tad more visible, and make documentation slightly more
> automatic.
.... and code slightly more robust. We are discussing this years after
a little step of introduction of prototypes to C was taken. That too
improved life a little. Tomorrow comes yet another idea in some brain
and we will have one more step towards better life.
> > Issues:
> > 3.1 Can compare with constants and globals only. Those should be
> > visible in the .h file
>
> What happens if one of those constants gets changed?
Constants won't change (or they would be variables!

. Globals may
change.
The very fact that the assertive declaration uses a global, implies
that it must depend on temporal value of the global. So (barring race
conditions), anything referring to a global will (luckily) change
behavior with the value of that global.
> > 3.3 In a sense it violates WYSIWYG nature of C. No problem with C++
>
> What is "WYSIWYG nature of C?" I've always found that C has a
> "WYGIWYG nature." That is, "what you get is what you get."
You are correct again. C is highly (and perhaps uniquely) WYSIWYG.
Assertive prototypes sort of violate that nature because assertions
won't be "seen in .c file". Implementation will happen "out of the
body of function".
However, assertive prototypes will still be highly predictable because
they actually steal the code from function body and put before (or
after) the body.
> > 3.5 Necessitates some error handler for assertion failure. (A good
> > code must already linking with some sort of <assert.h> or equivalent.)
>
> I should think it would throw an exception in C++.
> Socks
-Bhushit