#include <stdio.h>
int astrcmp(const char *, const char *);
int main (int argc, const char * argv[]) {
int i;
i = astrcmp(argv[1], argv[2]);
if ( i == 0)
printf(" \"%s\" equals \"%s\" ", argv[1], argv[2] );
else if ( i > 0 )
printf(" \"%s\" is greater than \"%s\" ", argv[1], argv[2] );
else if ( i < 0 )
printf(" \"%s\" is less than \"%s\" ", argv[1], argv[2] );
return 0;
}
int astrcmp(const char *s, const char *t){
for (; *s == *t; s++, t++){
if ( *s == 0)
return 0;
}
return ((*s - *t) > (*t - *s));
}
stepping through the code, it soon exits and gives the following on the console. I know there is an error in the code, but cannot get to it until I can step through it.
Thank you in advance.
Running…
Pending breakpoint 1 - ""main.c:3" resolved
gdb stack crawl at point of internal error:
[ 0 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (align_down+0x0) [0x11d2ff]
[ 1 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (step_into_current_inlined_subroutine+0x109) [0x6d5b2]
[ 2 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (inlined_function_update_call_stack+0x154a) [0x6ebbe]
[ 3 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (handle_inferior_event+0xbfe) [0x68332]
[ 4 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (fetch_inferior_event+0x125) [0x6abda]
[ 5 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (inferior_event_handler+0xd0) [0x7e9c4]
[ 6 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (handle_file_event+0x159) [0x7c8ac]
[ 7 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (process_event+0x81) [0x7c49e]
[ 8 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (gdb_do_one_event+0x46a) [0x7d33c]
[ 9 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (catch_errors+0x4d) [0x77487]
[ 10 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (start_event_loop+0x52) [0x7c4fd]
[ 11 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (captured_command_loop+0x12) [0x7821e]
[ 12 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (catch_errors+0x4d) [0x77487]
/SourceCache/gdb/gdb-768/src/gdb/inlining.c:1742: internal-error: step_into_current_inlined_subroutine: Assertion `current_inlined_subroutine_call_stack_start_pc() == stop_pc' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.