By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

RTTI Question: typeid() for structures

P: n/a
My C++ compiler (gcc 3.3.1) is prefixing a number in front on a
user-defined structure when I invoke typeid() on it. Can anyone
explain why? [Look at the funny thing I have to do in the macro
definition to get rid of that]

Source code follows:
Bhat

////////////////////////////////////////////////
#include <iostream>
#include <typeinfo>
#include <strings.h>

using namespace std;

#define TYPEID(x) cout << #x << ": " << strpbrk(typeid(x).name(),
"_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV WXYZ") << endl;
struct sampleStruct
{
char c;
short s;
int i;
};

int
main()
{
TYPEID(sampleStruct);

sampleStruct whatsmytype;
TYPEID(whatsmytype);
}

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
The C++ implementation may return anything it wants when name() is called.
It could be a human-friendly name, a mangled name, a curse word, an empty
string, your mothers maiden name, etc...

"Generic Usenet Account" <us****@sta.samsung.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
My C++ compiler (gcc 3.3.1) is prefixing a number in front on a
user-defined structure when I invoke typeid() on it. Can anyone
explain why? [Look at the funny thing I have to do in the macro
definition to get rid of that]

Source code follows:
Bhat

////////////////////////////////////////////////
#include <iostream>
#include <typeinfo>
#include <strings.h>

using namespace std;

#define TYPEID(x) cout << #x << ": " << strpbrk(typeid(x).name(),
"_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV WXYZ") << endl;
struct sampleStruct
{
char c;
short s;
int i;
};

int
main()
{
TYPEID(sampleStruct);

sampleStruct whatsmytype;
TYPEID(whatsmytype);
}

Jul 23 '05 #2

P: n/a

"Generic Usenet Account" <us****@sta.samsung.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
My C++ compiler (gcc 3.3.1) is prefixing a number in front on a
user-defined structure when I invoke typeid() on it. Can anyone
explain why? [Look at the funny thing I have to do in the macro
definition to get rid of that]

Source code follows:
Bhat

////////////////////////////////////////////////
#include <iostream>
#include <typeinfo>
#include <strings.h>

using namespace std;

#define TYPEID(x) cout << #x << ": " << strpbrk(typeid(x).name(),
"_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV WXYZ") << endl;
struct sampleStruct
{
char c;
short s;
int i;
};

int
main()
{
TYPEID(sampleStruct);

sampleStruct whatsmytype;
TYPEID(whatsmytype);
}


The C++ implementation may return anything it wants when name() is called.
It could be a human-friendly name, a mangled name, a curse word, an empty
string, your mothers maiden name, etc...
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.