I have an application where I want to generate unique error codes
depending on the path the code takes (call stack). 

Example: 
If the calling sequence is:
funcA() -> funcB() -> funcC() -> failure!
The error code can be 784.
If the calling sequence is:
funcA() -> funcB() -> funcD() -> failure!
The error code can be 456.

Now the only two real requirements is that each error code is completely
unique, regardless of the combination paths that can be taken. I wish I
took a heavier interest in mathematics in college as I bet there is a
solution to this. And the second is the ideas/solutions be in standard C
with no operating system calls to implement.

A problem you might foresee are function loop backs/recursion. Don't
take this into consideration.

I'd like to assign each function a unique id and that id can be applied
to the general path taken algorithm.

What I don't need are appending solutions or debug suggestions. I know
how to turn debugging on and off and having a trace output of stuff
isn't what I'm looking for. Rather just a unique identifier. So when I
get the identifier I can decode it to see the path taken. I don't need
clients running in debug mode all the time, nor do I want them trying to
reproduce an unreproducible problem. 

My first idea was to append the unique ids into a section of memory.
This got really bad really fast. After a call stack of 32 deep into
functions the string was extremely long! Using a base 36 number
(A-Z,a-z,0-9) the string got to be 128 bytes. I'd give each function a
unique id; e.g., funcA() could have been "00Y1". I have lots of
functions to map! Each function having 4 bytes in the string. 

It was getting to be "work" so I know there has to be a better solution
in C as this isn't a unique concept.

Thank you and I appreciate your ideas, Chris

Reply via email to