Could C++ do this without the #pragma

From: Steven T. Hatton (susudata_at_setidava.kushan.aa)
Date: 05/31/04


Date: Mon, 31 May 2004 10:07:01 -0400

Stroustrup says this:

http://www.research.att.com/~bs/bs_faq2.html#macro

"So, what's wrong with using macros?"

[...Macros are really bad (I paraphrase - STH)...]

"And yes, I do know that there are things known as macros that doesn't
suffer the problems of C/C++ preprocessor macros. However, I have no
ambitions for improving C++ macros. Instead, I recommend the use of
facilities from the C++ language proper, such as inline functions,
templates, constructors (for initialization), destructors (for cleanup),
exceptions (for exiting contexts), etc."

The GCC documentation says this:

http://gcc.gnu.org/onlinedocs/gcc-3.4.0/gcc/C---Interface.html#C++%20Interface
"Declarations and Definitions in One Header"

"C++ object definitions can be quite complex. In principle, your source code
will need two kinds of things for each object that you use across more than
one source file. First, you need an interface specification, describing its
structure with type declarations and function prototypes. Second, you need
the implementation itself. It can be tedious to maintain a separate
interface description in a header file, in parallel to the actual
implementation. It is also dangerous, since separate interface and
implementation definitions may not remain parallel."

[...use our cool #pragmas and don't mess with source/implementation...(I
paraphrase - STH) ]

Now, my question is, can the same thing GCC is doing with #pragmas be done
with something internal to C++? I can't see how. I understand that
#pragma is basically a way for the implementation to introduce behavior not
specified in the standard, so there really isn't a direct contradiction to
what Stroustrup id saying. Nonetheless, I would like to be sure there is
no way to accomplish this within the C++ language proper.

-- 
STH 
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org  SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org


Relevant Pages

  • C++ as a better C
    ... When Stroustrup talking about C++ as a better C, ... Why inline functions are comparative to macros here? ... Why pass-by-reference is easy in C++? ...
    (comp.lang.cpp)
  • Re: simple vector versus simple array
    ... >> You imply that Joe's solution breaks an interface. ... > functions and macros behave differently in some ways, ... that AND and OR cannot be given to APPLY or FUNCALL. ... whereas a compiler-macro can be macroexpanded to see its ...
    (comp.lang.lisp)
  • Re: Dredging up patterns
    ... >> As a general rule, ... > "Using macros for optimization instead of inline declarations ... more space efficient than macros or compiler-macros, ... > detail, latter affects the interface. ...
    (comp.lang.lisp)
  • Re: simple vector versus simple array
    ... >> functions and macros behave differently in some ways, ... compiler which is not able to inline the functions). ... macro is part of the interface in some cases? ... > that AND and OR cannot be given to APPLY or FUNCALL. ...
    (comp.lang.lisp)
  • Re: ILC2005: McCarthy denounces Common Lisp, "Lisp", XML, and Rahul
    ... There's good uses of macros and bad uses of macros. ... > Take for example an interface builder type of application. ... Later you change that frame definition ... internals of your Common Lisp implementation. ...
    (comp.lang.lisp)