Re: correct way to initialize pointer...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/24/06, Momchil Velikov <velco@xxxxxxxxx> wrote:
Mandeep Sandhu wrote:
> Hi All,
>
> This is more of a 'C' question than a kernel one. But since i'll be
> putting this
> in a module, I thought I'd ask here too...
>
> Whats the correct way to initialize a pointer?
>
> 1. char *p = 0;
> OR
> 2. char *p = NULL;

"[#3] An integer constant _expression_ with  the  value  0,  or
such  an  _expression_  cast  to type void *, is called a null
pointer   constant."

You could do char *p = 1 - 1; char *q = 0; char *r = 1 / 2;
if you wish.

Thats an interesting way of writing zero! :)

I read some time ago (can't remember where!), that 0 is not always
an invalid address. Though I think the C compiler is supposed to generate
one for any such assignments (as shown above). Is this a C standard?
Are all compilers supposed to do it?

Shouldn't NULL be a better choice so that we can #define it to an invalid
value, where this #define is specific to an architechture?? CMIIW.

Thanks,
-mandeep



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux