Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: What is the data structure of a NULL? Date: Sat, 28 Dec 2019 21:12:25 -0800 Organization: None to speak of Lines: 70 Message-ID: <87k16fr9za.fsf@nosuchdomain.example.com> References: <87sgl4rc3w.fsf@nosuchdomain.example.com> <87o8vsqh5l.fsf@nosuchdomain.example.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="e3b117bf55650e4ec854fd7e333c3408"; logging-data="5002"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19O9X4t3CWikn0U7laVkmic" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cancel-Lock: sha1:nPU62Zr/vo4/uFzJ6C+WVCYFTj8= sha1:aNUr2x+MdKn0ComhN/3wr/Djmbw= Xref: csiph.com comp.lang.c++:70756 Ned Latham writes: > Keith Thompson wrote: >> Ned Latham writes: >> > Keith Thompson wrote: >> > > T writes: >> > > > >> > > > In C++, when you make a call to Windows Kernel32.dll >> > > > and it wants a NULL for one or more of its parameters, >> > > > what exactly is the structure of a NULL? A 32 bit >> > > > word full of zeros? >> > > >> > > You might get better answers if you explained why you want to know. >> > > >> > > If you're making a call from C++, you can just pass a null pointer >> > > value such as nullptr or NULL. The compiler needs to know how >> > > it's represented. You probably don't. >> > >> > But knowing it can be useful, I use (void*) to cast integers and >> > unsigned integers for functions that require pointer parameters, >> > and if (parm) to test them. >> >> Why? Can you share some examples? > > Why? In what way does the above need elucidation? You indicated that it's useful to know how a null pointer is represented. How is it useful? Most of the time, the representation doesn't matter. >> If a function takes a pointer parameter, you need to pass a pointer >> value to it. There are cases where it might make sense to cast >> an integer to void*, but they're rare. > > Irelevant. Irrelevant to what exactly? >> If you need to pass a null >> pointer, use nullptr or NULL. > > Why? (void*) (well okay (defined_type*), actually) does perfectly well, > and it does away with the clumsiness of switching between constant > and variable. Do you mean "(void*)0"? Yes, that's a valid null pointer constant, but why do you prefer it to NULL or nullptr? What do you mean by "switching between constant and variable"? >> (In some low-level code, you might >> store pointer values in integers.) > > Indeed. > >> As for `if (parm)`, that's >> valid for any scalar type. > > Precisely. Precisely what? If parm is of pointer type, `if (parm)` tests whether it's a null pointer or not, regardless of how it's represented. You seemed to be using that as an example of why it's useful to know how pointers are represented. It isn't. Perhaps I'm missing something. What exactly was your point? -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com [Note updated email address] Working, but not speaking, for Philips Healthcare void Void(void) { Void(); } /* The recursive call of the void */