#include <stdio.h>
#include <stdlib.h>
#include <uuid/uuid.h>
int main(void) {
puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
uuid_t uuid;
int uuid_generate_time_safe(uuid);
printf("%x",uuid);
return EXIT_SUCCESS;
}
I just wonder why uuid is not 16 bytes long?
I use DEBUG to view the memory, It is indeed not 16 bytes.
And I use libpcap to develop my program, The uuid is not unique.
I just tried your program on my system, and
uuidis 16 bytes long. But your program doesn’t display its size.The line:
isn’t a call to the
uuid_generate_time_safefunction, it’s a declaration of that function withuuidas the (ignored) name of the single parameter. (And that kind of function declaration isn’t even valid as of the 1999 standard, which dropped the old “implicitint” rule.)Your
printfcall:has undefined behavior;
"%x"requires an argument of typeunsigned int.If you look in
/usr/include/uuid/uuid.h, you’ll see that the definition ofuuid_tis:The correct declaration of
uuid_generate_time_safe(seeman uuid_generate_time_safe) is:You don’t need that declaration in your own code; it’s provided by the
#include <uuid/uuid.h>.Because
uuid_tis an array type, the parameter is really of typeunsigned char*, which is why the function is seemingly able to modify its argument.Here’s a more correct program that illustrates the use of the function:
On my system, I got the following output:
See the man page for information about why the “uuid not generated safely” message might appear.
Note that I had to install the
uuid-devpackage to be able to build and run this program.