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 6 1685
Zara wrote:
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.
>
Should it work, from the Standard point of view, or am i missing
something?
Best regards,
Zara
On Mon, 25 Sep 2006 06:06:52 +0200, Zara <me*****@dea.spamcon.org>
wrote:
>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
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.
On Mon, 25 Sep 2006 07:32:26 +0200, Rolf Magnus <ra******@t-online.de>
wrote:
>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]
Zara wrote:
>>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.
Then it's the version. I'm using 4.1.2, and with -pedantic, it says:
error: zero-size array ‘data’
[OT]
Zara <me*****@dea.spamcon.orgwrote:
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?
I see you found that your problem was with a size-0 array, but this
article by Alf P. Steinbach has a couple other approaches, along with
their pro's and con's: http://home.no.net/dubjai/win32cpptu...y_size.doc.pdf
--
Marcus Kwok
Replace 'invalid' with 'net' to reply This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kevin Brown |
last post by:
Is there anyway to generate this type of resulting HTML table from
this XML using XSLT? Basically I need to be able to consult 2 trees of
data to generate the HTML, but I have not been able to...
|
by: Pat Turner |
last post by:
Hi,
I have some XML like this:
<family>
<person name="bob">
<father ref="../../person" />
</person>
<person name="charlie">
<child ref="../../person" />
|
by: Mike |
last post by:
Hey!
I've started to use templates for storing arrays of doubles.
The template itself will then be passed on to a linked-list.
My problem is that Im not 100% familiar with how templates
are...
|
by: WittyGuy |
last post by:
Hi,
What is the major difference between function overloading and function
templates?
Thanks!
http://www.gotw.ca/resources/clcm.htm for info about ]
|
by: Mark Miller |
last post by:
I have a scheduled job that uses different XSL templates to transform XML
and save it to disk. I am having problems with the code below. The problem
shows up on both my development machine (Windows...
|
by: Greg |
last post by:
I am trying to convert an older console application written in C to a
visual application using several Borland VCL components (open and save
dialogs). I am declaring input and output stream...
|
by: Piper707 |
last post by:
I need help with using a general template which would process all tags
other than the ones for which specific templates have been written.
My XML looks like this:
<ITEMS>...
|
by: NewToCPP |
last post by:
Hi,
I am just trying to find out if there is any strong reason for not
using Templates. When we use Templates it is going to replicate the
code for different data types, thus increasing the...
|
by: arnuld |
last post by:
this one was much easier and works fine. as usual, i put code here for
any further comments/views/advice:
--------- PROGRAMME ------------
/* Stroustrup: 5.9 exercise 7
STATEMENTS:
Define a...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
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,...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |