Thursday, November 15, 2012

[Cpp-Programming] Re: Class out-of-scope problem?

You say you are storing the nameas a "char *".
Do you make a COPY of the  name, or just point your char * variable to the name? What is the return value of the member function call - does it point to newly allocated memory, or to a local string that goes out of scope when the function returns?
 
On Friday, October 12, 2012 10:34:25 AM UTC-7, Harry Potter wrote:
Thank you for responding.  The name of the label is stored as a char*, and a member function call returns the name of the variable as written for the assembler.  To test the class, I wrote several lines that output the label name to the console window at different points in the compilation.  One line before the function-processing call, the name is displayed properly.  One of the first tasks of the latter is to print the name of the label.  It displays garbage.  Later on in the course of the compiler, it crashes.  There could be no interference from another application or anther part of the same application, as it is a simple console tool.  I plan to see if maybe the address of either the Label class or the name string is off and get back to you on Monday.

On Friday, October 12, 2012 12:15:47 PM UTC-4, Beyeler Studios wrote:
Hi Harry ^^

from your post I guess Label contains some kind of a string (char pointer)? And when you're later trying to read that string, it appears garbled?
This can happen, when you dereference a char pointer e.g. to a deleted character array. The memory might be overwritten by another allocation, but the address might still be valid for your programme (that way you don't get an access violation exception).
See if you can trace your Label pointer l and find out two things: 1) is it really l that you are passing to the function in question? 2) do you delete l (or the pointer to the "name of the function" inside the object) before you dereference it in the function in question?

Next time try to at least add the definition (minimum fields, constructor/deconstructor) of Label, or try to explain more, how the "name of the function" is represented, how you're passing it around and how you're trying to access it in your code.

Best,
BeyelerStudios

On Thursday, 11 October 2012 16:20:03 UTC+2, Harry Potter wrote:
Hi!  I've been creating a cross-platform C compiler using ANSI/ISO C++ and am running into a problem.  I have a function that handles variable declarations.  This function declares a label within the auto namespace (Term correction?) as:
 
        Label* l=new Label;     //Tmp. label
 
If the routine reaches a '(' in the input to indicate a function, it calls another function.  Before the function call, the name of the function is retrieved correctly.  However, within the called function, the function name returns garbage.  What can cause this?  I'm thinking that maybe the class loses scope during the call.  I'm sorry that I'm not revealing more code; there's alot of code, and it's very vcomplex.  I'd appreciate any advice.

--
You received this message because you are subscribed to the Google Groups "C++ Programming" group.
To view this discussion on the web visit https://groups.google.com/d/msg/cpp-programming/-/a_LPfelqcqIJ.
To post to this group, send email to cpp-programming@googlegroups.com.
To unsubscribe from this group, send email to cpp-programming+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cpp-programming?hl=en.