2

I understand the difference between unsigned and unsigned int. But my question is a bit different.

I am ioremaping(linux) a particular memory and i want to read the memory. I did the following thig :

func()
{
    unsigned int *p;

    p = (unsigned int *)ioremap(ADDR,8*sizeof(unsigned int));
    for (i = 0; i <= 7; i++)
       pr_err("p[%d] = %d", i, p[i]);
}

This works perfectly. But I see a standard code doing the same and using (unsidned *) instead of (unsigned int *). That is p is of unsigned *p.

func()
{
    unsigned *p;

    p = (unsigned *)ioremap(ADDR,8*sizeof(unsigned));
    for (i = 0; i <= 7; i++)
       pr_err("p[%d] = %d", i, p[i]);
}

I would like to know if it is a good programming practice(platform independent code??). If yes please sate the reason.

Sandeep
  • 18,356
  • 16
  • 68
  • 108
  • 2
    "*I understand the difference between unsigned and unsigned int.*" -- Just what do you think the difference is? (There is none, other than spelling.) And you should use `%u` or `%x`, not `%d`, to print unsigned values. – Keith Thompson Oct 30 '13 at 02:30

2 Answers2

3

unsigned and unsigned int has no difference at all.

Therefor, unsigned * and unsigned int * has no difference at all.


Similarly, long is short for long int, int is short for signed int, etc. There is no difference in one to the other. The only exception to notice is that whether plain char is signed or unsigned is implementation-defined, so it's not the same as signed char.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
1

unsigned and unsigned int are the same type, so are pointers to them. The int is implicit.

Grady Player
  • 14,399
  • 2
  • 48
  • 76