tags:

views:

56

answers:

3

i am learning c programming. I am trying to make my own program similar to ls command but with less options.what i am doing is taking input directory/file name as argument and then gets all directory entry with dirent struct(if it is directory) .

After it i use stat() to take all information of the file but here is my problem when i use write() to print these value its fine but when i want to print these with printf() i get warninng : format ‘%ld’ expects type ‘long int’, but argument 2 has type ‘__uid_t’. I don't know what should use at place of %ld and also for other special data types.

+4  A: 

There is no format specifier for __uid_t, because this type is system-specific and is not the part of C standard, and hence printf is not aware of it.

The usual workaround is to promote it to a type that would fit the entire range of UID values on all the systems you are targeting:

printf("%lu\n", (unsigned long int)uid); /* some systems support 32-bit UIDs */
Alex B
A: 

You could cast it to a long int:

printf("foobar: %ld\n", (long int)your_uid_t_variable);
Johannes Weiß
A: 

In POSIX, uid_t is unsigned short for 32bit platforms and unsigned int for 64bit ones.
Ideally, you should write like this:

# ifdef __i386__
  printf("uid: %d\n", (unsigned short)uid);
# else
  printf("uid: %d\n", (unsigned int)uid);
# endif

Or simply:

printf("uid: %d\n", uid);

..which should give no warnings for both variants.

Andrejs Cainikovs