"Paul Herring" <[EMAIL PROTECTED]> wrote:
> Christopher Carver <[EMAIL PROTECTED]> wrote:
> > I have an application where I want to generate unique error
> > codes depending on the path the code takes (call stack).
Why?
>
> [snip]
>
> Sounds like what a lot of other tools out there do during
> development work. Sounds like you want something for
> production however. Not something I'd advocate. However...
>
> Have a global variable, and (re-)hash it every time at the
> start of a function call (or wherever in your code you want
> a path to be noted) with either a fixed number or the
> current line number in that file. The eventual hash should
> give you some sort of indication of the path taken.
>
> static hash_val;
> void rehash(long l_val){
> // your hash function here to change hash_val with l_val)
> }
>
> int foo(...){
> rehash(__LINE__);
> // body of foo();
> }
>
> float bar(...){
> rehash(__LINE__);
> // body of bar();
> }
>
> ... etc.
>
> Generating the lookup table will not be fun however.
If you simply want the call stack, then implement a call
stack. Hash the result when you need it.
Uniquely enumerating traversal paths can produce some
very large numbers quite quickly, especially if heavy
recursion is involved. Do you actually need an error
code (number), or do you simply need to show where the
code is up to?
--
Peter