-1

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.

ysap
  • 7,723
  • 7
  • 59
  • 122
piratos
  • 29
  • 2

2 Answers2

2

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.

sjsam
  • 21,411
  • 5
  • 55
  • 102
0
printf("%s is located at 0x%08x in %s\n",argv[2],(unsigned int)fprc_func,argv[1]);

The first %s refers to the argv[2].

The %08x refers to fprc_func in hex with 8 zeroes, where fprc_func is a function pointer returned by GetProcAddress. The (unsigned int) cast the address to unsigned integer (never negative).

The last %s refers to argv[1].

More info about printf format can be found here: http://www.cplusplus.com/reference/cstdio/printf/

raymai97
  • 806
  • 7
  • 19
  • Let me add an example: assuming you use `%03i`, if the int is 12, it will show 012, if the int is 3, it will show 003. – raymai97 Apr 23 '16 at 13:17