How to comprehend the "Header File"???

3

322322

When I open the Header File "isostream" in VC ,I can't understand a
lot of thing ! Could anybody tell me ? Thanks a lot $B!*(B

// iostream standard header

#if _MSC_VER >
1000 ////?????????
#pragma once
#endif

#ifndef _IOSTREAM_
#define _IOSTREAM_
#include <istream>

#ifdef _MSC_VER
#pragma pack(push,8)
#endif /* _MSC_VER */
_STD_BEGIN ////???????
why not "namespace std{...}"
// OBJECTS
static ios_base::Init _Ios_init;
extern _CRTIMP istream cin;
extern _CRTIMP ostream cout;
extern _CRTIMP ostream cerr, clog;
// CLASS _Winit
class _CRTIMP _Winit {
public:
_Winit();
~_Winit();
private:
static int _Init_cnt;
};
// WIDE OBJECTS
static _Winit _Wios_init;
extern _CRTIMP wistream wcin;
extern _CRTIMP wostream wcout, wcerr, wclog;
_STD_END
#ifdef _MSC_VER
#pragma pack(pop)
#endif /* _MSC_VER */

#endif /* _IOSTREAM_ */

/*
* Copyright (c) 1994 by P.J. Plauger. ALL RIGHTS RESERVED.
* Consult your license regarding permissions and restrictions.
*/
 
O

Obnoxious User

When I open the Header File "isostream" in VC ,I can't understand a lot
of thing ! Could anybody tell me ? Thanks a lot ï¼

// iostream standard header

If you can't understand it, you're not ready to open it yet.
 
J

Jim Langston

322322 said:
When I open the Header File "isostream" in VC ,I can't understand a
lot of thing ! Could anybody tell me ? Thanks a lot $B!*(B

// iostream standard header

#if _MSC_VER > 1000

It seems that some version of the Microsoft compiler came out with the
extension #pragma once. It wasn't in version 1000 (maybe 1.0? hard to
tell) so if the defined variable _MSC_VER is 1000 or less, #pragma once
won't be compiled since the compiler wouldn't understand it.
#pragma once
#endif

#ifndef _IOSTREAM_
#define _IOSTREAM_
#include <istream>

#ifdef _MSC_VER
#pragma pack(push,8)
#endif /* _MSC_VER */
_STD_BEGIN ////???????
why not "namespace std{...}"

Because if it is being compiled as C then _STD_BEGIN is defined empty. If
it is being compiled as C++ it is defined as namespace std {

[SNIP]
 
L

Lance Diduck

322322 said:
#endif  /* _MSC_VER */
_STD_BEGIN                                                ////???????
why not "namespace std{...}"

Because if it is being compiled as C then _STD_BEGIN is defined empty.  If
it is being compiled as C++ it is defined as namespace std {

[SNIP]
Another reason is that when the library was first written, the
compiler did not support namespaces, and the macros were never
changed. Also, using macro like this makes it easier to version
lbiraries, i.e. it doesnalays have to expand to namepsace std{

Lance
Lance
 
I

Ian Collins

Jim said:
Because if it is being compiled as C then _STD_BEGIN is defined empty. If
it is being compiled as C++ it is defined as namespace std {
You jest?

Try feeding that to a C compiler a see how many pages of errors you get.

The header (like just about all standard library implementations) is
written to work with prehistoric compilers lacking namespace support.
 
J

Jim Langston

Ian said:
You jest?

Try feeding that to a C compiler a see how many pages of errors you
get.

The header (like just about all standard library implementations) is
written to work with prehistoric compilers lacking namespace support.

Well, this is the code in the yyals.h file.

#if defined(__cplusplus)
#define _STD_BEGIN namespace std {
#define _STD_END }
#define _STD ::std::
// ...
#else /* __cplusplus */
#define _STD_BEGIN
#define _STD_END
#define _STD
//...
#endif

if __cplusplus is defined, it expands it, else it makes it empty.

That is why Windows defines it and uses it. Yes, they probably use it in
places that will never be compiled in a C compiler, but that's why they use
_STD_BEGIN instead of namespace std {
 
I

Ian Collins

Jim said:
Well, this is the code in the yyals.h file.

#if defined(__cplusplus)
#define _STD_BEGIN namespace std {
#define _STD_END }
#define _STD ::std::
// ...
#else /* __cplusplus */
#define _STD_BEGIN
#define _STD_END
#define _STD
//...
#endif

if __cplusplus is defined, it expands it, else it makes it empty.

That is why Windows defines it and uses it. Yes, they probably use it in
places that will never be compiled in a C compiler, but that's why they use
_STD_BEGIN instead of namespace std {
That's in the platform specific code, the library will be designed to
work without namespaces, most are.
 
3

322322

Well, this is the code in the yyals.h file.

#if defined(__cplusplus)
#define _STD_BEGIN namespace std {
#define _STD_END }
#define _STD ::std::
// ...
#else /* __cplusplus */
#define _STD_BEGIN
#define _STD_END
#define _STD
//...
#endif

if __cplusplus is defined, it expands it, else it makes it empty.

That is why Windows defines it and uses it. Yes, they probably use it in
places that will never be compiled in a C compiler, but that's why they use
_STD_BEGIN instead of namespace std {

Thanks a lot !! ^_^! I got the answer!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top