This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
Hi, Richard: Thank you very much for replying. There is an error when build with -m64 -O[2, 3, s]. I have just tried with -m32 and no error. GCC (Red Hat 4.4.6-4) GCC (Red Hat 4.4.7-3) chenzhi
//============================================================================
// Name : hello.cpp
// Author : chenzhi
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C, Ansi-style
//============================================================================
#include <stdio.h>
template<typename _Type> class array_t
{
size_t m_count;
_Type* m_array[15];
public:
array_t(void){
m_count = 0;
}
~array_t(void){
}
size_t add(_Type *_ptr){
m_array[m_count] = _ptr;
return ++m_count;
}
size_t get_count(void) const {
return m_count;
}
const _Type &get_item(size_t _index) const {
return *m_array[_index];
}
_Type *find(_Type *_ptr) const {
for(size_t i = 0; i < m_count; ++i){
_Type *_item = m_array[i];
if(*_item == *_ptr)
return _item;
}
return 0;
}
};
struct IDString
{
unsigned char m_id;
unsigned char m_len;
char m_str[6];
friend bool operator ==(const IDString &_r1, const IDString &_r2){
return (_r1.m_id==_r2.m_id) ? true : false;
}
};
class IDString_Array : public array_t<IDString>
{
IDString *find_idstring(unsigned char _id){
return find((IDString*)&_id);
}
public:
IDString_Array(IDString *_id_strings, size_t _count){
for(size_t i = 0; i < _count; ++i){
add(&_id_strings[i]);
}
}
~IDString_Array(void){
}
const char *get_default_string(void){
IDString *_ids = find_idstring(2);
return (_ids) ? _ids->m_str : "GCC (-m64) Optimization -O(2,3,s) Error!";
}
void print_all(void){
size_t n = get_count();
for(size_t i = 0; i < n; ++i){
const IDString &_ids = get_item(i);
printf("id=%u\tlen=%u\tstring=\"%s\"\n", _ids.m_id, _ids.m_len, _ids.m_str);
}
}
};
static IDString g_idstrings[] = {
{1, 4, "id=1"},{2, 4, "id=2"},{3, 4, "id=3"},{4, 4, "id=4"},
{5, 4, "id=5"},{6, 4, "id=6"},{7, 4, "id=7"},{8, 4, "id=8"}
};
int main(void)
{
IDString_Array idstring_array(g_idstrings, sizeof(g_idstrings)/sizeof(g_idstrings[0]));
idstring_array.print_all();
const char *_str = idstring_array.get_default_string();
int len = printf("%s\n", _str);
return len;
}
Attachment:
Makefile
Description: Binary data
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |