C++ Precompiler: Same as C Precompiler?

J

James Kanze

"James Kanze" <[email protected]> wrote in message
On Jun 11, 2:24 am, "JohnQ" <[email protected]>
wrote:
"No, but I think it will be with the next release of the
standard. There is a very extensive common subset, however."
"C++ doesn't have any of the features what were added in C99.
Things like a variable number of arguments for macros.
There are also small differences with regards to predefined
symbols: C doesn't (and won't) have __cplusplus, for example.
This is intentional."
So templates are implemented strictly in the compiler then or is that
implementation-specific?

Well, how anything is implemented is implementation-specific,
but yes, templates have nothing to do with the preprocessor;
they are defined at the language level (phases 7 and later), and
normally implemented at that level as well.

How could it be otherwise, given the rules for e.g. name
binding, scope, etc.?
(Aside: Your post's header info contains:
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable <<-- Is this the problem?)

I suspect so; there's no reason for it to be there. On the
other hand, I don't know where it is getting introduced. (Maybe
the firewall here? It's not present when I don't post behind a
firewall.)
 
J

James Kanze

JohnQ wrote:
They have to be implemented by the compiler. Templates use types and
the preprocessor being a simple text processor has no concept to type.

They have scope, which the preprocessor doesn't. They
participate in function overloading, which the preprocessor
doesn't. Etc., etc.

The question is really a little ridiculous, I think. Even a
superficial glance shows that templates are integrated into the
language. Traditionally, CFront implemented them at the linker
stage, using a pre-linker. Well after preprocessing.

Of course, it's possible to simulate some of the functionality
of templates using the preprocessor; I can still remember using
<generic.h>. But it's very definitly a simulation, using text
based substitution, and not real templates (which operate on
language entities, and not text). Thus, for example, given:

typedef int A ;
typedef int B ;

instantiating a class defined using <generic.h> on A and on B
would result in two distinct instantiations, since the names
differed textually, whereas there will only be one template
instantiation, since the types are identical. And it was
impossible to instantiate a class defined using <generic.h> on a
nested class, since the textual name, Outer::Inner couldn't be
pasted to make a valid class name.
 
J

JohnQ

JohnQ wrote:
They have to be implemented by the compiler. Templates use types and
the preprocessor being a simple text processor has no concept to type.

"They have scope, which the preprocessor doesn't. They
participate in function overloading, which the preprocessor
doesn't. Etc., etc.

The question is really a little ridiculous, I think. Even a
superficial glance shows that templates are integrated into the
language. Traditionally, CFront implemented them at the linker
stage, using a pre-linker. Well after preprocessing.

Of course, it's possible to simulate some of the functionality
of templates using the preprocessor; I can still remember using
<generic.h>. But it's very definitly a simulation, using text
based substitution, and not real templates (which operate on
language entities, and not text)."

To me, "real" templates are the concept and not the C++-specific
incarnation.

"Thus, for example, given:

typedef int A ;
typedef int B ;

instantiating a class defined using <generic.h> on A and on B
would result in two distinct instantiations, since the names
differed textually, whereas there will only be one template
instantiation, since the types are identical. "

Yep, that's true, but hardly a deal breaker.

" And it was
impossible to instantiate a class defined using <generic.h> on a
nested class, since the textual name, Outer::Inner couldn't be
pasted to make a valid class name."

Do you have an example?

John
 

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,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top