get variable type & exception handling.

Is there a way to acquire the variable type for an object like as getsize(..)?. For example something like...

int x = 0;
cout << getType(x) << endl;

and have it print "int" or "Signed32BitInt" whatever, just something?

That was the main question. While on the topic...

Note * I am pretty sure that there is no compiler independent way to do this, but thought I would ask..

I am trying to set up a semi-cozy exception handling system in C++ similar to VB.NET's. I have come across where I have in an array class, checking bounds and printing if out of bounds. I would like to be able to print what was out of bounds, or some other specific information like type variable name or line of code that called it. I would like to be able to get what line of code on what page calls a function.
for example...

void something(int bubba)
{
if (bubba > 10)
{
//print here (main.cpp , line 20) from the line that called the function in main..
}
}


int main (..,..)
{
something(15); //let's say this is page main.cpp and line 20
}




If I am off track and someone has another idea about how to know what object goes out of bounds in an overloaded subsript bounds check, I would appreciate the input.


Speak.


Comments

  • : Is there a way to acquire the variable type for an object like as getsize(..)?. For example something like...
    :
    : int x = 0;
    : cout << getType(x) << endl;
    :
    : and have it print "int" or "Signed32BitInt" whatever, just something?
    :
    : That was the main question. While on the topic...
    :
    : Note * I am pretty sure that there is no compiler independent way to do this, but thought I would ask..
    :
    : I am trying to set up a semi-cozy exception handling system in C++ similar to VB.NET's. I have come across where I have in an array class, checking bounds and printing if out of bounds. I would like to be able to print what was out of bounds, or some other specific information like type variable name or line of code that called it. I would like to be able to get what line of code on what page calls a function.
    : for example...
    :
    : void something(int bubba)
    : {
    : if (bubba > 10)
    : {
    : //print here (main.cpp , line 20) from the line that called the function in main..
    : }
    : }
    :
    :
    : int main (..,..)
    : {
    : something(15); //let's say this is page main.cpp and line 20
    : }
    :
    :
    :
    :
    : If I am off track and someone has another idea about how to know what object goes out of bounds in an overloaded subsript bounds check, I would appreciate the input.
    :
    :
    : Speak.
    :
    :
    :


    I can give one idea on how to print the file & line..
    [code]
    void something(int bubba, char *file, int line)
    {
    if (bubba > 10)
    {
    printf("error: %s:%d
    ", file, line);
    //print here (main.cpp , line 20) from the line that called the function in main..
    }
    }

    int main( void )
    {
    something(15, __FILE__,__LINE__);

    return 0;
    }
    [/code]
    [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]

  • how would i get file & line?

    Speak
  • : how would i get file & line?
    :
    : Speak
    :

    Obviously you haven't compiled and ran my example. Go ahead, try it :)



    [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]

  • I apologize, I hadn;t compiled, I had read your message wrong. Anyway thank you, that gives me a good start.

    Speak



    : : Is there a way to acquire the variable type for an object like as getsize(..)?. For example something like...
    : :
    : : int x = 0;
    : : cout << getType(x) << endl;
    : :
    : : and have it print "int" or "Signed32BitInt" whatever, just something?
    : :
    : : That was the main question. While on the topic...
    : :
    : : Note * I am pretty sure that there is no compiler independent way to do this, but thought I would ask..
    : :
    : : I am trying to set up a semi-cozy exception handling system in C++ similar to VB.NET's. I have come across where I have in an array class, checking bounds and printing if out of bounds. I would like to be able to print what was out of bounds, or some other specific information like type variable name or line of code that called it. I would like to be able to get what line of code on what page calls a function.
    : : for example...
    : :
    : : void something(int bubba)
    : : {
    : : if (bubba > 10)
    : : {
    : : //print here (main.cpp , line 20) from the line that called the function in main..
    : : }
    : : }
    : :
    : :
    : : int main (..,..)
    : : {
    : : something(15); //let's say this is page main.cpp and line 20
    : : }
    : :
    : :
    : :
    : :
    : : If I am off track and someone has another idea about how to know what object goes out of bounds in an overloaded subsript bounds check, I would appreciate the input.
    : :
    : :
    : : Speak.
    : :
    : :
    : :
    :
    :
    : I can give one idea on how to print the file & line..
    : [code]
    : void something(int bubba, char *file, int line)
    : {
    : if (bubba > 10)
    : {
    : printf("error: %s:%d
    ", file, line);
    : //print here (main.cpp , line 20) from the line that called the function in main..
    : }
    : }
    :
    : int main( void )
    : {
    : something(15, __FILE__,__LINE__);
    :
    : return 0;
    : }
    : [/code]
    : [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]
    :
    :
  • : Is there a way to acquire the variable type for an object like as getsize(..)?. For example something like...
    :
    : int x = 0;
    : cout << getType(x) << endl;
    :
    : and have it print "int" or "Signed32BitInt" whatever, just something?
    :
    : That was the main question. While on the topic...
    :
    : Note * I am pretty sure that there is no compiler independent way to do this, but thought I would ask..
    :
    : I am trying to set up a semi-cozy exception handling system in C++ similar to VB.NET's. I have come across where I have in an array class, checking bounds and printing if out of bounds. I would like to be able to print what was out of bounds, or some other specific information like type variable name or line of code that called it. I would like to be able to get what line of code on what page calls a function.
    : for example...
    :
    : void something(int bubba)
    : {
    : if (bubba > 10)
    : {
    : //print here (main.cpp , line 20) from the line that called the function in main..
    : }
    : }
    :
    :
    : int main (..,..)
    : {
    : something(15); //let's say this is page main.cpp and line 20
    : }
    :
    :
    :
    :
    : If I am off track and someone has another idea about how to know what object goes out of bounds in an overloaded subsript bounds check, I would appreciate the input.
    :
    :
    : Speak.
    :

    [blue]As far as getting the type of a variable, I posted something that did that a few pages back on this forum. Here is the link: http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=3&MsgID=278508&Setting=A9999F0006 It may or may not be of use to you. It uses the [italic]typeinfo.h[/italic] header and makes use of a [italic]typeid[/italic] function.[/blue]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories