Article View: comp.std.c++
Article #3564constant-expression extension
From: Igor Boukanov
Date: Fri, 01 Mar 1996 17:03
Date: Fri, 01 Mar 1996 17:03
47 lines
2265 bytes
2265 bytes
My proposal is to change definition of the
"integral constant-expression"[5.19] to something like this:
An integral constant-expression is an expression that can be calculated
at the compilation phase.
And according to this one would be able to use inline
functions in constant-expressions and instead of writing:
#define ALIGN(number, base) ((number + base - 1) / base * base)
#define MAX(x, y) ((x > y) ? (x) : (y))
#define GRAD_TO_RADIAN(x) (x * 3.1415926 / 180)
char buf[ALIGN(50, sizeof(float))];
char buf2[MAX(sizeof(long), sizeof(double))];
const double angle = GRAD_TO_RADIAN(30);
one can write:
inline unsigned T align(unsigned number, unsigned base) {
return ((number + base - 1) / base * base);
}
template<class T> inline T max(T x, T y){
return (x > y) ? x : y;
inline double grad_to_radian(double x){
return x * 3.1415926 / 180;
}
char buf[align(50, sizeof(float))];
char buf2[max(sizeof(long), sizeof(double))];
const double angle = grad_to_radian(30);
So what do you think about this?
--
Regards,
Igor Boukanov (igor.boukanov@fi.uib.no).
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Technical Details
Message-ID:
<4h775a$m4s@ugress.uib.no>Path:
arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austernShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern From: boukanov@afrodite.fi.uib.no (Igor Boukanov) Newsgroups: comp.std.c++ Subject: constant-expression extension Date: 01 Mar 1996 09:03:14 PST Organization: Fysisk institutt, Universitetet i Bergen Approved: austern@isolde.mti.sgi.com Message-ID: <4h775a$m4s@ugress.uib.no> NNTP-Posting-Host: isolde.mti.sgi.com Summary: Such extension can reduce number of macros in programs. Keywords: constant-expression, macro X-Original-Date: 1 Mar 1996 16:03:54 GMT X-Newsreader: TIN [version 1.2 PL2] X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBMTcuBUy4NqrwXLNJAQFrLgH+NUBP2rhqYFPDLgzenmMNUlZqKPi2OGEj 74hZvZpMqyKChCgLzNHDTejDeNjimPQ6ugMHdtweKUsRJcxTwA9TYg== =fLS8 Originator: austern@isolde.mti.sgi.com