Discussion:
MAX_PATH vs. _MAX_PATH. What's the difference?
(too old to reply)
J
2005-04-29 00:42:41 UTC
Permalink
Excuse my rustiness with C programming. I have little experience
programming in the Windows environment.

stdlib.h has #define _MAX_PATH 260
windef.h has #define MAX_PATH 260

Why would one use one over the other and what is the significance of the
underscore in front of MAX_PATH?

J
Severian [MVP]
2005-04-29 04:27:38 UTC
Permalink
Post by J
Excuse my rustiness with C programming. I have little experience
programming in the Windows environment.
stdlib.h has #define _MAX_PATH 260
windef.h has #define MAX_PATH 260
Why would one use one over the other and what is the significance of the
underscore in front of MAX_PATH?
Standard ANSI C/C++ headers cannot include defines that begin with a
letter (with certain exceptions, such as E... for error codes), so
stdlib.h, which is part of ANSI C/C++, defines it with an underscore.

When you include <windows.h>, you have altogether left the realm of
standard C/C++, so #defines like MAX_PATH are OK.

--
Phillip Crews aka Severian
Microsoft MVP, Windows SDK
Posting email address is real, but please post replies on the newsgroup.
Sten Westerback
2005-04-29 06:08:39 UTC
Permalink
Post by Severian [MVP]
Post by J
Excuse my rustiness with C programming. I have little experience
programming in the Windows environment.
stdlib.h has #define _MAX_PATH 260
windef.h has #define MAX_PATH 260
Why would one use one over the other and what is the significance of the
underscore in front of MAX_PATH?
Standard ANSI C/C++ headers cannot include defines that begin with a
letter (with certain exceptions, such as E... for error codes), so
stdlib.h, which is part of ANSI C/C++, defines it with an underscore.
When you include <windows.h>, you have altogether left the realm of
standard C/C++, so #defines like MAX_PATH are OK.
And in the "real world" you allocate more than enough as paths can be
longer in NT. So a 1000 character buffer would be appropriate... unless
you really have a need to store thousands of them in memory.

- Sten
J
2005-04-29 17:01:56 UTC
Permalink
Post by Severian [MVP]
Standard ANSI C/C++ headers cannot include defines that begin with a
letter (with certain exceptions, such as E... for error codes), so
stdlib.h, which is part of ANSI C/C++, defines it with an underscore.
When you include <windows.h>, you have altogether left the realm of
standard C/C++, so #defines like MAX_PATH are OK.
--
Phillip Crews aka Severian
Microsoft MVP, Windows SDK
Posting email address is real, but please post replies on the newsgroup.
Thanx for your useful response!

J

Continue reading on narkive:
Loading...