Hi all,
How can i assing the name of a CString variable to another CString? I mean,

CString xxx;yyy;

xxx=NameOfVar(yyy);

is there any function or something similar to do this.
Thanks...

Ilter Suat

Re: name of variable by lallous

lallous
Mon Dec 15 04:26:40 CST 2003

Hello,

You can create an alias for 'yyy' named 'xxx' as:

CString yyy, *xxx;

xxx = &y;

Now 'xxx' and 'yyy' reference the same CString instance.

--
Elias

"ilter suat" <ilter@datatronics.com.tw> wrote in message
news:O0CxgRuwDHA.1760@TK2MSFTNGP10.phx.gbl...
> Hi all,
> How can i assing the name of a CString variable to another CString? I
mean,
>
> CString xxx;yyy;
>
> xxx=NameOfVar(yyy);
>
> is there any function or something similar to do this.
> Thanks...
>
> Ilter Suat
>
>
>
>



Re: name of variable by ilter

ilter
Mon Dec 15 06:32:18 CST 2003

Hi,

I guess i couldnt explain clearly. I want to learn the variable name, not
the content.

CString xxx, yyy;
xxx=NameOfVar(yyy);

AfxMessageBox("Name of Variable : " + xxx);

--> The output :
Name of Variable : yyy

"lallous" <lallous@lgwm.org> wrote in message
news:OS%237gbvwDHA.3744@TK2MSFTNGP11.phx.gbl...
> Hello,
>
> You can create an alias for 'yyy' named 'xxx' as:
>
> CString yyy, *xxx;
>
> xxx = &y;
>
> Now 'xxx' and 'yyy' reference the same CString instance.
>
> --
> Elias
>
> "ilter suat" <ilter@datatronics.com.tw> wrote in message
> news:O0CxgRuwDHA.1760@TK2MSFTNGP10.phx.gbl...
> > Hi all,
> > How can i assing the name of a CString variable to another CString? I
> mean,
> >
> > CString xxx;yyy;
> >
> > xxx=NameOfVar(yyy);
> >
> > is there any function or something similar to do this.
> > Thanks...
> >
> > Ilter Suat
> >
> >
> >
> >
>
>



Re: name of variable by Scott

Scott
Mon Dec 15 06:43:49 CST 2003

ilter suat wrote:
> Hi,
>
> I guess i couldnt explain clearly. I want to learn the variable name, not
> the content.
>
> CString xxx, yyy;
> xxx=NameOfVar(yyy);
>
> AfxMessageBox("Name of Variable : " + xxx);

No way. The compiler converts variable names into addresses. The names
are not part of the program at run time. Explain what you are trying to
accomplish and someone can probably suggest another way.

--
Scott McPhillips [VC++ MVP]


Re: name of variable by tom_usenet

tom_usenet
Mon Dec 15 07:56:45 CST 2003

On Mon, 15 Dec 2003 16:20:33 +0800, "ilter suat"
<ilter@datatronics.com.tw> wrote:

>Hi all,
>How can i assing the name of a CString variable to another CString? I mean,
>
>CString xxx;yyy;
>
>xxx=NameOfVar(yyy);
>
>is there any function or something similar to do this.

What's wrong with:
xxx = "yyy";

Why do you want the name of a variable in a CString anyway? What are
you trying to do?

Tom

C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html

Re: name of variable by Lucas

Lucas
Mon Dec 15 10:11:39 CST 2003

Hi,
mmm... I think you can do it with some macros and preprocessing, but I doubt
the usefulness of it.

Lucas/

"ilter suat" <ilter@datatronics.com.tw> wrote in message
news:O0CxgRuwDHA.1760@TK2MSFTNGP10.phx.gbl...
> Hi all,
> How can i assing the name of a CString variable to another CString? I
mean,
>
> CString xxx;yyy;
>
> xxx=NameOfVar(yyy);
>
> is there any function or something similar to do this.
> Thanks...
>
> Ilter Suat
>
>
>
>



Re: name of variable by ilter

ilter
Mon Dec 15 10:44:34 CST 2003


I was trying to write an error handling function which can returns variable
names. I just wanted to learn if it is possible or not.

Thanks
Ilter Suat

"Scott McPhillips [MVP]" <scottmcp@mvps.org.nowhere> wrote in message
news:OE7MSlwwDHA.4060@TK2MSFTNGP11.phx.gbl...
> ilter suat wrote:
> > Hi,
> >
> > I guess i couldnt explain clearly. I want to learn the variable name,
not
> > the content.
> >
> > CString xxx, yyy;
> > xxx=NameOfVar(yyy);
> >
> > AfxMessageBox("Name of Variable : " + xxx);
>
> No way. The compiler converts variable names into addresses. The names
> are not part of the program at run time. Explain what you are trying to
> accomplish and someone can probably suggest another way.
>
> --
> Scott McPhillips [VC++ MVP]
>



Re: name of variable by Douglas

Douglas
Mon Dec 15 14:11:56 CST 2003

There is no such constuct in any compiler i've ever seen.

It is quite possible (and easy) to implement, I guess there hasn't been any
great demand for it so language authors and compiler writers haven't
bothered.

I have my own language and compiler and just for grins I coded this ability
into it. It was really simple to do. I created 2 expressions
_identifier()
_identifier_nomangle()

When the compiler encounters "_identifier(xxx)" it simply adds the
identifier name from the internal symbol table into the string literal list
and returns as a string literal node. The _identifier_nomangle version is
for identifiers (like function names) that get appended with type
information. So you can do exacly what you want with my language and
compiler (utterly useless to you of course).

It *might* be possible to use the address of the variable to lookup the
variable's name in the symbol table in the .exe file itself, however:

a) It would take quite a bit of work to code
b) Local variables do not generally have symbol table entries.
c) The symbol table can be stripped from a .exe externally

So there is no really generic way to do it, but take a look at how the
ASSERT (or ASSERTE) macro's work. They pass the whole assertion string to a
display function so when you have something like this:

ASSERT(xyz != 0);

Or some such, the whole string gets passed to the display function so the
reported error shows not only the line and source number, but the actual
expression that failed.


"ilter suat" <ilter@datatronics.com.tw> wrote in message
news:e2K7LewwDHA.2316@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> I guess i couldnt explain clearly. I want to learn the variable name, not
> the content.
>
> CString xxx, yyy;
> xxx=NameOfVar(yyy);
>
> AfxMessageBox("Name of Variable : " + xxx);
>
> --> The output :
> Name of Variable : yyy
>
> "lallous" <lallous@lgwm.org> wrote in message
> news:OS%237gbvwDHA.3744@TK2MSFTNGP11.phx.gbl...
> > Hello,
> >
> > You can create an alias for 'yyy' named 'xxx' as:
> >
> > CString yyy, *xxx;
> >
> > xxx = &y;
> >
> > Now 'xxx' and 'yyy' reference the same CString instance.
> >
> > --
> > Elias
> >
> > "ilter suat" <ilter@datatronics.com.tw> wrote in message
> > news:O0CxgRuwDHA.1760@TK2MSFTNGP10.phx.gbl...
> > > Hi all,
> > > How can i assing the name of a CString variable to another CString? I
> > mean,
> > >
> > > CString xxx;yyy;
> > >
> > > xxx=NameOfVar(yyy);
> > >
> > > is there any function or something similar to do this.
> > > Thanks...
> > >
> > > Ilter Suat
> > >
> > >
> > >
> > >
> >
> >
>
>



Re: name of variable by ilter

ilter
Mon Dec 15 21:18:24 CST 2003

Hi,

Yes Douglas, I wanted to write a function/macro like ASSERT(). But it must
also send the variable name. AFAIK, ASSERT() doesnt send the whole
experession. It just sends app. name,source file and line number. If i am
wrong,pls correct me. I checked the Afxasert.cpp in the MFC\SRC.

// format message into buffer
wsprintf(szMessage, _T("%s: File %hs, Line %d"), lpszAppName, lpszFileName,
nLine);

I just wanted to learn if it is possible or not. Actually i dont have enough
time to deal with this now.

Thanks...

"Douglas Peterson" <Tergiver@nospam.msn.com> wrote in message
news:utv6xe0wDHA.1984@TK2MSFTNGP09.phx.gbl...
> There is no such constuct in any compiler i've ever seen.
>
> It is quite possible (and easy) to implement, I guess there hasn't been
any
> great demand for it so language authors and compiler writers haven't
> bothered.
>
> I have my own language and compiler and just for grins I coded this
ability
> into it. It was really simple to do. I created 2 expressions
> _identifier()
> _identifier_nomangle()
>
> When the compiler encounters "_identifier(xxx)" it simply adds the
> identifier name from the internal symbol table into the string literal
list
> and returns as a string literal node. The _identifier_nomangle version is
> for identifiers (like function names) that get appended with type
> information. So you can do exacly what you want with my language and
> compiler (utterly useless to you of course).
>
> It *might* be possible to use the address of the variable to lookup the
> variable's name in the symbol table in the .exe file itself, however:
>
> a) It would take quite a bit of work to code
> b) Local variables do not generally have symbol table entries.
> c) The symbol table can be stripped from a .exe externally
>
> So there is no really generic way to do it, but take a look at how the
> ASSERT (or ASSERTE) macro's work. They pass the whole assertion string to
a
> display function so when you have something like this:
>
> ASSERT(xyz != 0);
>
> Or some such, the whole string gets passed to the display function so the
> reported error shows not only the line and source number, but the actual
> expression that failed.
>
>
> "ilter suat" <ilter@datatronics.com.tw> wrote in message
> news:e2K7LewwDHA.2316@TK2MSFTNGP10.phx.gbl...
> > Hi,
> >
> > I guess i couldnt explain clearly. I want to learn the variable name,
not
> > the content.
> >
> > CString xxx, yyy;
> > xxx=NameOfVar(yyy);
> >
> > AfxMessageBox("Name of Variable : " + xxx);
> >
> > --> The output :
> > Name of Variable : yyy
> >
> > "lallous" <lallous@lgwm.org> wrote in message
> > news:OS%237gbvwDHA.3744@TK2MSFTNGP11.phx.gbl...
> > > Hello,
> > >
> > > You can create an alias for 'yyy' named 'xxx' as:
> > >
> > > CString yyy, *xxx;
> > >
> > > xxx = &y;
> > >
> > > Now 'xxx' and 'yyy' reference the same CString instance.
> > >
> > > --
> > > Elias
> > >
> > > "ilter suat" <ilter@datatronics.com.tw> wrote in message
> > > news:O0CxgRuwDHA.1760@TK2MSFTNGP10.phx.gbl...
> > > > Hi all,
> > > > How can i assing the name of a CString variable to another CString?
I
> > > mean,
> > > >
> > > > CString xxx;yyy;
> > > >
> > > > xxx=NameOfVar(yyy);
> > > >
> > > > is there any function or something similar to do this.
> > > > Thanks...
> > > >
> > > > Ilter Suat
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Re: name of variable by adebaene

adebaene
Tue Dec 16 11:01:06 CST 2003

"ilter suat" <ilter@datatronics.com.tw> wrote in message news:<#uxqLrywDHA.2452@tk2msftngp13.phx.gbl>...
> I was trying to write an error handling function which can returns variable
> names. I just wanted to learn if it is possible or not.
>

It is possible in a totally non portable manner by reading the debug
pdb file associated with your exe (the variable names are NOT in the
executable). See SymInitialize and all functions from DbgHelp.dll, but
if you go that way you re more and less writing a debugger (and of
course it won't work on release version).

Arnaud
MVP - VC

Re: name of variable by Igor

Igor
Tue Dec 16 11:38:34 CST 2003

"ilter suat" <ilter@datatronics.com.tw> wrote in message
news:%23uxqLrywDHA.2452@tk2msftngp13.phx.gbl...
> I was trying to write an error handling function which can returns
variable
> names. I just wanted to learn if it is possible or not.

Macros can do it:

#deinfe Stringize1(x) #x
#define Stringize(x) Stringize1(x)

CString y = Stringize(blah blah blah);
// the same as
CString y = "blah blah blah";

--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken



Re: name of variable by Joe

Joe
Tue Dec 16 11:55:09 CST 2003

ilter suat wrote:
> Hi all,
> How can i assing the name of a CString variable to another CString? I
> mean,
>
> CString xxx;yyy;
>
> xxx=NameOfVar(yyy);
>
> is there any function or something similar to do this.
> Thanks...
>
> Ilter Suat

Ilter,

If this is for debugging purposes, you could use the "stringize"
capability of the compiler and put the expression in a macro.
For example:
------------------------------------------------------------------------
-----------------
#include <iostream>

#define PR(var) std::cout << #var << " = " << var << std::endl

int main(void)
{
int x, y , result;

x = 123;
y = 456;
result = x + y;

PR(x);
PR(y);
PR(result);

return 0;
}
------------------------------------------------------------------------
-----------------


Joe



Re: name of variable by James

James
Tue Dec 16 12:04:08 CST 2003

> CString xxx, yyy;
> xxx=NameOfVar(yyy);

Isn't that just:

CString xxx, yyy;
xxx="yyy";



--
Truth,
James Curran
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
(note new day job!)

"ilter suat" <ilter@datatronics.com.tw> wrote in message
news:e2K7LewwDHA.2316@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> I guess i couldnt explain clearly. I want to learn the variable name, not
> the content.
>
> CString xxx, yyy;
> xxx=NameOfVar(yyy);
>
> AfxMessageBox("Name of Variable : " + xxx);
>
> --> The output :
> Name of Variable : yyy
>
> "lallous" <lallous@lgwm.org> wrote in message
> news:OS%237gbvwDHA.3744@TK2MSFTNGP11.phx.gbl...
> > Hello,
> >
> > You can create an alias for 'yyy' named 'xxx' as:
> >
> > CString yyy, *xxx;
> >
> > xxx = &y;
> >
> > Now 'xxx' and 'yyy' reference the same CString instance.
> >
> > --
> > Elias
> >
> > "ilter suat" <ilter@datatronics.com.tw> wrote in message
> > news:O0CxgRuwDHA.1760@TK2MSFTNGP10.phx.gbl...
> > > Hi all,
> > > How can i assing the name of a CString variable to another CString? I
> > mean,
> > >
> > > CString xxx;yyy;
> > >
> > > xxx=NameOfVar(yyy);
> > >
> > > is there any function or something similar to do this.
> > > Thanks...
> > >
> > > Ilter Suat
> > >
> > >
> > >
> > >
> >
> >
>
>



Re: name of variable by ilter

ilter
Tue Dec 16 20:20:54 CST 2003

> If this is for debugging purposes, you could use the "stringize"
> capability of the compiler and put the expression in a macro.

Hi,

Thats great! Thank u very much. I tried and it is working now. But why cant
i use this operator in the release version? Can u explain briefly?

Thanks all...




Re: name of variable by Joe

Joe
Wed Dec 17 11:00:54 CST 2003

ilter suat wrote:
>> If this is for debugging purposes, you could use the "stringize"
>> capability of the compiler and put the expression in a macro.
>
> Hi,
>
> Thats great! Thank u very much. I tried and it is working now. But
> why cant i use this operator in the release version? Can u explain
> briefly?
>
> Thanks all...

Ilter,

The stringizing operator is handled during the preprocessor phase, so
the code is independent of the "build" being done. It will work for any
build.


Joe