Search code examples
cfunctionexitexplain

Can somebody explain these lines in this code?


In this source-code of Arwin I saw :

fprc_func = GetProcAddress(hmod_libname,argv[2]);

if(fprc_func == NULL)
{
    printf("Error: could find the function in the library!\n");
    exit(-1);
}
printf("%s is located at 0x%08x in %s\n",argv[2],(unsigned int)fprc_func,argv[1]);

Why we use exit(-1) and not use exit(1) here ?

Also please explain the printf statement in a understanding way.


Solution

  • Whether to use exit(-1) or exit(1) for failure is a personal choice.

    POSIX compliant code uses 1 or EXIT_FAILURE for failures

    In

    printf("%s is located at 0x%08x in %s\n",argv[2],(unsigned int)fprc_func,argv[1]);
    

    Two strings argv[2] & argv[1] (as specified by %s) and an unsigned hexadecimal integer fprc_func (as specified by 0x%08x) are printed. The %08 in 0x%08x is for setting the width to eight. See printf doc.