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
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>