473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Output using c++ compiler


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! ]

Feb 23 '06 #1
7 1791
John wrote:
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
--
Please remove capital As from my address when replying by mail
Feb 23 '06 #2

John wrote:
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! ]

Feb 23 '06 #3

peter koch larsen wrote:
John wrote:
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).

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! ]

Feb 23 '06 #4
peter koch larsen wrote:
[..]
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
--
Please remove capital As from my address when replying by mail

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

Feb 23 '06 #5
I am happy with any format. Warnings or error messages. Just
that I want the fibonacii numbers in the output.

Thanks,
--j

Victor Bazarov wrote:
peter koch larsen wrote:
[..]
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
--
Please remove capital As from my address when replying by mail


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

Feb 24 '06 #6

John wrote:
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 Bazarov wrote:
peter koch larsen wrote:
[..]
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
--
Please remove capital As from my address when replying by mail


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

Feb 24 '06 #7

John wrote:
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! ]

Feb 24 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Trevor | last post by:
Hello, Please bear with me, I am trying to learn C++. I am implementing some error/debug functions which format a message and output it to a C++ stream. I would like to design it using one low...
3
by: W. Cerven | last post by:
I am using the C++ STL container "list" to create a template nested list. Attached are my basic code and compiler errors. Oddly enough, I when I create a non-template version of this nested list,...
4
by: rossum | last post by:
I have been looking at exceptions as I need to get better at using them. I came across an interesting effect, demonstrated below. When I ctrl-Z the input to throw an ios_base::failure, the...
6
by: Allan M. Bruce | last post by:
I just recently took a C programming test (which was a total farce - but thats not the point). The code below is a combination of two questions that were included in the test and I was hoping to...
32
by: spibou | last post by:
Is the output of the C preprocessor deterministic ? What I mean by that is , given 2 compilers which conform to the same standard, will their preprocessors produce identical output given as input...
7
by: Nena | last post by:
Hi there, I'm trying to include the Numerical Recipes for C++ for the Dev-C++ Editor Version. But so far I've failed. Therefore I've copied all head-files (for example nr.h) into the folder...
18
by: rajpal_jatin | last post by:
int main() { int k; union jatin{ int i :5; char j :2; }; union jatin rajpal; k= sizeof(rajpal);
87
by: pereges | last post by:
I have a C program which I created on Windows machine. I have compiled and executed the program on windows machine and it gives me the consistent output every time i run it. for eg. input a = 2,...
2
by: sanjay | last post by:
Hi All, I have a doubt in understanding the output of the following program that i executed on my system. I was using DevC++ IDE which uses minGW based compiler. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.