 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Zara Guest
|
Posted: Mon Sep 25, 2006 9:06 am Post subject: Using templates with arrays |
|
|
I have been trying to substitute the macro that comes with the
compiler with the following template:
template <typename ITEM,size_t SIZE>
inline size_t arraySize(ITEM const (&array)[SIZE]) {
return SIZE;
}
AFAIK, it is compliant with the standard, and it should work.
In fact, it works perfectly on Borland C++ 2006, but it fails on GCC
3.4.1.
Should it work, from the Standard point of view, or am i missing
something?
Best regards,
Zara |
|
| Back to top |
|
 |
Zara Guest
|
Posted: Mon Sep 25, 2006 9:10 am Post subject: Re: Using templates with arrays |
|
|
On Mon, 25 Sep 2006 06:06:52 +0200, Zara <me_zara (AT) dea (DOT) spamcon.org>
wrote:
| Quote: | I have been trying to substitute the macro that comes with the
compiler with the following template:
template <typename ITEM,size_t SIZE
inline size_t arraySize(ITEM const (&array)[SIZE]) {
return SIZE;
}
..
In fact, it works perfectly on Borland C++ 2006, but it fails on GCC
3.4.1.
|
So sorry for this comment, it works on both. The problem comes from
using an empty intilizer list for the array:
int data[]={};
This compiles on GCC and not on BCB, but after reading the relevant
part of C++Std, it should not compile (8.5.1-4 and footnote 91). My
fault.
Regrads,
Zara |
|
| Back to top |
|
 |
Rolf Magnus Guest
|
Posted: Mon Sep 25, 2006 9:10 am Post subject: Re: Using templates with arrays |
|
|
Zara wrote:
| Quote: | In fact, it works perfectly on Borland C++ 2006, but it fails on GCC
3.4.1.
So sorry for this comment, it works on both. The problem comes from
using an empty intilizer list for the array:
int data[]={};
This compiles on GCC and not on BCB, but after reading the relevant
part of C++Std, it should not compile (8.5.1-4 and footnote 91).
|
My guess is that you forgot to turn on all the warning options for gcc. |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Sep 25, 2006 9:10 am Post subject: Re: Using templates with arrays |
|
|
Zara wrote:
| Quote: | I have been trying to substitute the macro that comes with the
compiler with the following template:
template <typename ITEM,size_t SIZE
inline size_t arraySize(ITEM const (&array)[SIZE]) {
return SIZE;
}
AFAIK, it is compliant with the standard, and it should work.
In fact, it works perfectly on Borland C++ 2006, but it fails on GCC
3.4.1.
|
The code is fine and it is a very common teqnique used for getting size
of an array.
| Quote: |
Should it work, from the Standard point of view, or am i missing
something?
Best regards,
Zara |
|
|
| Back to top |
|
 |
Zara Guest
|
Posted: Mon Sep 25, 2006 9:10 am Post subject: Re: Using templates with arrays |
|
|
On Mon, 25 Sep 2006 07:32:26 +0200, Rolf Magnus <ramagnus@t-online.de>
wrote:
| Quote: | Zara wrote:
In fact, it works perfectly on Borland C++ 2006, but it fails on GCC
3.4.1.
So sorry for this comment, it works on both. The problem comes from
using an empty intilizer list for the array:
int data[]={};
This compiles on GCC and not on BCB, but after reading the relevant
part of C++Std, it should not compile (8.5.1-4 and footnote 91).
My guess is that you forgot to turn on all the warning options for gcc.
|
[OT]
I do use:
-pedantic -pedantic-errors -Wall -Werror -std=c++98
It seems ther is no diagnostic for this error.
[OT] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|