|
another question:
why should i use
if (pointer == NULL)
and not
if (pointer == 0)
is there any difference between those two ?
is this historically?
does NULL has got any advantages?
thanks in advance
bernhard
Sometimes I think the surest sign for intelligent life elsewhere in
the universe is that none of them ever tried to contact us.
|
|
|
|
|
Well, I'd tend to use the second form (if (pointer == 0) ) because "0" is the standard name for the null pointer since C was invented. NULL is a macro of dubious reputation included in stddef.h and stdio.h , altough MS folks also provide it in windows.h for your convenience.
Why do I prefer unadorned 0 instead of NULL ? Most of the time it doesn't really matter which syntax you use, and NULL is admittedly a bit clearer, but the problem with this macro is that its definition can vary from compiler vendor to compiler vendor (some define it as a bare 0, others as ((void *)0) ). Worse yet, as this macro tends to be defined independently by different library writters (as it is the case in windows.h ) ocassionally you can end up with different NULL definitions across compilation units. In extreme pathological situations this can make a difference.
Another, more practical, reason to prefer 0 over NULL is that you don't have to rely on any previously included header.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
thank you for your quick answer..
the only reason why i'm asking this is that most of the programmers with c - background i know use the NULL for pointers.. i just use 0 and wanted to ask, before i make a real flaw all over my code (i am a little bit a pointer-o-holic)
thanks
bernhard
Sometimes I think the surest sign for intelligent life elsewhere in
the universe is that none of them ever tried to contact us.
|
|
|
|
|
Using NULL or 0 is basically a style issue of religious proportions. After reading your message, I did a little research on NULL and 0. Here are some interesting facts.
1. NULL is usually defined as 0 or ((void *) 0). The later being an valid alternative to help prevent people from doing stupid stuff like assigning NULL to a non-pointer variable. This is in fact not at all portable.
2. When NULL and 0 are used in the context of pointers, they don't actually mean that the pointer is zero. The C and C++ standards state that the actual value stored in a pointer to represent NULL or 0 is machine depended and need not be zero. It is the compiler's job to make sure that comparisons against NULL or 0 perform the proper tests.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
I agree with you in that this is a very tiny issue that receives a disproportionate amount of interest. With respect to your fact #1, there's an interesting associated problem: the following line of code
char *p=(void*)0; is legal C, but illegal in C++, as this latter language forbids implicit casting from void* to any other pointer type, due to type safety reasons. So even this seemingly innocent definition for NULL has unexpected side effects.
This surprising fact and a lot more info about the null pointer you can find it on Stroustrup's The Design and Evolution of C++, §11.2.3.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Ah, good point that I forgot about.
I found this in WINDEF.H.
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif
I need to check that reference out. Thanks.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
As has been said, BOOL exists for C API programming, where no bool exists. It is a BAD idea to use it if you can avoid it. To get rid of warnings when converting BOOL to bool do this:
bool bResult = (::SomeDodgyAPIFunction()>0);
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Really ? I've not noticed that.
In any case, one should not program poorly because Microsoft tools are broken.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
That's what I thought it would do, I find that perfectly readable ( and it's the same as BOOL, except BOOL can use any non-zero value for true in theory ).
The easiest way I can think of to trace bool is to write a bool handler for IOStreams that prints the word true or false, and then use ostringstream to format a string before tracing it. ( This is also safe, which sprintf ISN'T ).
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
how to enum all loaded modules ?
thanx
|
|
|
|
|
For NT/2K/XP systems only, there exists an SDK library called PSAPI including the function EnumProcessModules that seems to do what you want (check it out here).
For 9x/ME (and optionally all of the other systems except NT), the way to go is using the ToolHelp32 functions (in KERNEL32) CreateToolhelp32Snapshot , Module32First and Module32Next .
All of this is bundled into a single sample executable (for both families of OSs) MODLIST.EXE offered by Microsoft which you can have a look at here. It's written in VB, but I guess you can easily port it to VC++ (you might even post an article with the results here in CodeProject )
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanx , but i know that , i needed a way to enum all modules that are currently loaded and not by a individual process
thanx again
|
|
|
|
|
If you already knew that, then you're almost there! Iterate thru all active processes with EnumProcesses (if using EnumProcessModules ) or Process32First and Process32Next (if you're leaning toward the second approach).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
once again , thanx
i will try that..
|
|
|
|
|
|
Hello All,
Working on image lists, my attention was drawn to *.icl file extensions. I was told it is simply a resource DLL with only icons, which means I could also create it by creating a DLL and renaming.
Is there any more I need to know about the *.icl file extension?
Why is it used intead of the *.dll extensions?
Someone called it the Icon library file, is this correct?
Best regards,
Paul.
Paul Selormey, Bsc (Elect Eng), MSc (Mobile Communication) is currently Windows open source developer in Japan, and open for programming contract anywhere!
|
|
|
|
|
An .ICL is a DLL created by MicroAngelo. It's got icons as well as some other stuff used by MA itself, like text descriptions of the icons.
--Mike--
My really out-of-date homepage
He who laughs last, didn't get the punchline and is just laughing so he won't look silly.
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan.
|
|
|
|
|
Thanks for the prompt response. I got to the MicroAngelo home page but there is no link to the *.icl "structure" (format). Anyway, I could get some information on all that is included in the *.icl. I can easily load the images/icons, however, just in case some of the information there could be of interest.
BTW, do you know of sources I could use to create the simple dll/icl files from my own programs?
Best regards,
Paul.
Paul Selormey, Bsc (Elect Eng), MSc (Mobile Communication) is currently Windows open source developer in Japan, and open for programming contract anywhere!
|
|
|
|
|
The last I looked, which admittedly was a couple of years ago, ICL files were 16-bit DLLs, so the Win32 APIs won't work with them. (I don't think you can even do a LoadLibrary() on a 16-bit DLL from 32-bit code.)
The tiny description of ICL on Wotsit's Format says:An .ICL file -- ICon Library, as used by icon editors like Microangelo -- is a renamed 16-bit Windows .DLL (an NE format executable) which typically contains nothing but a resource section. The ICL extension seems to be used by convention. I don't know where MacroAngelo stores its additional info in the file.
--Mike--
My really out-of-date homepage
He who laughs last, didn't get the punchline and is just laughing so he won't look silly.
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan.
|
|
|
|
|
Hi,
if you are interested in resource-only DDLs you could read my article
at http://www.codeproject.com/dll/iconsst.asp
Bye!
SoftechSoftware
Davide Calabro'
davide_calabro@yahoo.com
http://www.softechsoftware.it
|
|
|
|
|
Davide Calabro wrote:
if you are interested in resource-only DDLs you could read my article
at http://www.codeproject.com/dll/iconsst.asp
Thanks, no really. I know how to create resource only dll with the VC+. I was hoping for a simple resouce compiler sources (in my response to Mike)
Best regards,
Paul.
Paul Selormey, Bsc (Elect Eng), MSc (Mobile Communication) is currently Windows open source developer in Japan, and open for programming contract anywhere!
|
|
|
|
|
when i Textout an char each time, there would be a leading space which would be too large when the space is set to tmMAXWIDTH, or it can not align properly when use GetTextExtentPoint32 to get the font size and adjust the space according the font size.
what's the solution of this problem?
thanks
one is the other who absorbs the thoughts of others
|
|
|
|
|
if i have a pointer to a variable, how using the pointer can the variable be changed?
|
|
|
|
|
The * (dereference) operator:
int *vpiPointer;
int viSomeValue = 5;
vpiPointer = &viSomeValue;
*vpiPointer = 3;
ASSERT(viSomeValue == 3);
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
I am having trouble with the behaviour of popup windows. I have a graphing program the displays 4 graphs. I want to select a graph and have it display in a new dialog, that can be moved around or minmized (much like Matlab plots)
How can I make these dialogs stop covering the main dialog and go to the back?? (they cover up the main program even if not active)
When they are minimised they do not enter the task bar but rather float above it. Is it possible to make them enter the task bar in WinNT??
I am using a new class CPopChart to start a new chart dialog from my original dialog with
class CDialog : OnPopChart() {
CPopChart pchart;
pChart.Create(IDD_POPUP,pWnd);
};
---
|
|
|
|