[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Skeleton C++ header bug

From: Hans Aberg
Subject: Re: Skeleton C++ header bug
Date: Thu, 27 Dec 2001 20:32:20 +0100

At 19:41 +0100 2001/12/27, Akim Demaille wrote:
>| -- In view of that "stderr" is a macro, not a part of the C++ language, it
>| cannot be put in a C++ "namespace" construct.
>That stderr is a macro or not is irrelevant and only bound to your
>libc and how you use it.  It's just C, and there is no such thing as
>namespaces in C.

That is the case: The old C names have under the new C++ standard been put
into the namespace std under C++, even though, of course, under C there is
no change.

So it means that if a C <name> is implementable in C++, it will be named
std::<name> under C++. But stderr is a preprocessor macro, not a C language
construct, and so it will remain so under C++.

On my computer, stderr will under C expand to
but under C++ to
So the namespace std is under C++ put in after the macro expansion.

I start to wonder what is exported to the linker. :-)

>I'll do that.


However, in view of that I was able to make a true C++ file (by my tweaks),
my interest for the C/C++ skeleton file is dropping off.

One funny thing, though, is that the stack interface, now in C++ became
explicit. One might turn back to a common C/C++ skeleton file by making
this stack interface into macros.

The C++ interface is:
template<class T>
class my_stack {
  typedef /* User defined */ size_type;
  typedef /* User defined */ difference_type;
  typedef /* User defined */ reference;
  struct iterator {
    iterator& operator++() { /* User defined */ return *this; }
    my_stack::reference operator*() const;
    bool operator!=(const iterator& rhs) const;
    iterator operator+(difference_type) const;
    iterator operator-(difference_type) const;
  size_type size() const;
        iterator begin();
        iterator end();
  iterator erase(iterator first, iterator last);
  void push_back(const T& x);
        void pop_back();
        reference back();
#define YYSTACK(type) my_stack<type>

In order to get this working with C, one would merely introduce more macros
corresponding to these functions:
  #define YYSTACK_PUSH(x) ...
  #define YYSTACK_POP ...

Right now, in my C++ skeleton file, one can for stack choose between
std::deque (default), std::vector and std::list, or make a custom stack
using the interface above.

  Hans Aberg

reply via email to

[Prev in Thread] Current Thread [Next in Thread]