Output using c++ compiler

J

John

I want to output the stuff computed using the compiler using template
metaprogrms
(not at runtime but compile time). An easy example is to output the set
of
fibonacii numbers at compile time instead of run time. (using maybe
error messages/
warnings...? Any other way except the output code generated).

Anyone knows if this is possible to do in g++? In general c++?

Thanks,
--j


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
V

Victor Bazarov

John said:
I want to output the stuff computed using the compiler using template
metaprogrms
(not at runtime but compile time). [...]

Anyone knows if this is possible to do in g++? In general c++?

Not possible in Standard C++. Ask in 'gnu.g++.help' about g++.

V
 
P

peter koch larsen

John said:
I want to output the stuff computed using the compiler using template
metaprogrms
(not at runtime but compile time). An easy example is to output the set
of
fibonacii numbers at compile time instead of run time. (using maybe
error messages/
warnings...? Any other way except the output code generated).

Anyone knows if this is possible to do in g++? In general c++?

It is. In fact, the first demonstration of template metaprogramming
techniques was a program to demonstrate how to calculate prime numbers
- outputting them in errormessages. Google should let you find the
original program; I once found it on the net.
Apart as an intellectual exercise the program will be of no use, of
course.

/Peter
Thanks,
--j


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
V

Victor Bazarov

peter said:
[..]
In fact, the first demonstration of template metaprogramming
techniques was a program to demonstrate how to calculate prime numbers
- outputting them in errormessages. [..]

Is there a requirement that the compiler actually prints error messages
in any particular form?

V
 
P

peter koch

peter said:
It is.

/Peter
Well... on second thoughts and after reading Victors reply, I must say
that I agree with him. The standard does not in anyway mandate the
format of errormessages, so you would of course run into compiler
dependent behaviour.
That said, my guess is that most - if not all - compilers could be made
to print at least the first few fibonacci-numbers inside errormessages
using rather simple template techniques.

/Peter


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
J

John

I am happy with any format. Warnings or error messages. Just
that I want the fibonacii numbers in the output.

Thanks,
--j

Victor said:
peter said:
[..]
In fact, the first demonstration of template metaprogramming
techniques was a program to demonstrate how to calculate prime numbers
- outputting them in errormessages. [..]

Is there a requirement that the compiler actually prints error messages
in any particular form?

V

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
P

peter koch

John said:
I am happy with any format. Warnings or error messages. Just
that I want the fibonacii numbers in the output.

What Victor hinted at is that a conforming compiler might simply abort
the compilation with e.g. the message "ERROR!". This is not very
helpful and unlikely to be found in practice. A more realistic problem
could be that the compiler limits the number of errormessages - perhaps
to show only the first error. Portable code is thus impossible.
Now if you still want those compile-time fibonacci-numbers as
errormessages from your compilation, my best advice would be to google
for that primenumber generating program i mentioned in my first post.
This program should give you enough insight to enable you to produce
fibonacci numbers instead.

/Peter
Thanks,
--j

Victor said:
peter said:
[..]
In fact, the first demonstration of template metaprogramming
techniques was a program to demonstrate how to calculate prime numbers
- outputting them in errormessages. [..]

Is there a requirement that the compiler actually prints error messages
in any particular form?

V

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
R

roberts.noah

John said:
I want to output the stuff computed using the compiler using template
metaprogrms
(not at runtime but compile time). An easy example is to output the set
of
fibonacii numbers at compile time instead of run time. (using maybe
error messages/
warnings...? Any other way except the output code generated).

Anyone knows if this is possible to do in g++? In general c++?

Two books in the C++ in Depth Series should help: Generic Programming
and Template Metaprogramming. These two books should help you a great
deal. You could also just look at the code to BOOST_STATIC_ASSERT.

It _is_ impossible to write "portable" code (what they really mean is
standard) because in reality you are creating an ill formed program.
Different compilers will display the errors differently, as they are
free to do so, but in reality you can predictably cause certain output
to appear /somewhere/ in the error report.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 

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,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top