MOD54415 Compiler "undefined for this scope"
-
- Posts: 192
- Joined: Mon Dec 17, 2012 6:24 am
MOD54415 Compiler "undefined for this scope"
Hey all - attached is my test program - can't figure out why OSTimeDelay() and upkt. are throwing a compiler error "undefined for this scope" - can someone take a look and tell me what I missed? This program is being set up to take an incoming data packet and light the LEDs on the board based on what letter was pressed..
- Attachments
-
UDP Send Receive main.cpp
- (7.55 KiB) Downloaded 407 times
Re: MOD54415 Compiler "undefined for this scope"
Some things i spotted.
#1) in the function DataHandler, you do not have a variable defined for "data[]"
#2) in the function DataHandler, inside the "default:" switch you misspelled OSTimeDelay 2 times, it should be "OSTimeDly"
Since your not doing anything with the variable "data" you could just change the switch statement from "switch (data)" to "switch (*data_pointer) "
Also your case statements need to be changed form case "a": to case 'a': use single quote.
#1) in the function DataHandler, you do not have a variable defined for "data[]"
#2) in the function DataHandler, inside the "default:" switch you misspelled OSTimeDelay 2 times, it should be "OSTimeDly"
Since your not doing anything with the variable "data" you could just change the switch statement from "switch (data)" to "switch (*data_pointer) "
Also your case statements need to be changed form case "a": to case 'a': use single quote.
-
- Posts: 192
- Joined: Mon Dec 17, 2012 6:24 am
Re: MOD54415 Compiler "undefined for this scope"
I actually did get rid of the array - I was planning to do that - just forgot. Thanks for catching the spelling error too. I still have the "upkt not declared in this scope" error showing up at the line "PBYTE data_pointer = upkt.GetDataBuffer();" - which puzzles me (not good at C++ yet) because the UdpReaderMain() function also has the method declaration in it and it's not calling an error either...
-
- Posts: 192
- Joined: Mon Dec 17, 2012 6:24 am
Re: MOD54415 Compiler "undefined for this scope"
So I eliminated my function (DataHandler() ) and just pasted the whole thing into the UDPReaderMain() while(1) loop and I get no errors - it has compiled, and I'm getting ready to test. I'd rather have it as a function. Could it be because I didn't use the UDP constructor in my initial code for the DataHandler() subroutine? example:
UDPPacket upkt(&fifo, 0 * TICKS_PER_SECOND);
that would be my novice guess as to why...
UDPPacket upkt(&fifo, 0 * TICKS_PER_SECOND);
that would be my novice guess as to why...
Re: MOD54415 Compiler "undefined for this scope"
Regarding spelling errors, nbeclipse has an autocomplete function. Start typing the function, then <ctl> space to autocomplete.
Re: MOD54415 Compiler "undefined for this scope"
HINT 1: To help you get more folks to read your code, if it is a large sample you want to share, I would suggest using https://gist.github.com/. Paste the code in there and then put the resulting link in your message. I know I'm incredibly lazy but I don't want to download a file, extract it, load it into an editor and then delete it all, when I can just click on a link. I'm sure I'm not alone, seulater is a saint but some of us are sinners.
HINT 2: Without looking at your code I would encourage you to get used to using the Type ahead feature of Eclipse. Type osti and then hit ctrl-space and you'll never get the capitalization or spelling of OSTimeDly wrong again. I use it for just about everything, sometimes I get to the last letter and then hit ctrl-space, i usually don't bother worrying about capitalization as ctrl-space doesn't care and will find all matches, when there's only one it will correct the capitalization and complete the entry.
HINT 3: use the auto-formatting (Source->Format) tool. I'm working with students and it's the first thing I do and then they immediately see their incorrectly nested structures. You can customize how the formatting looks with the Window>-Preferences->C/C++->Code Style.
HINT 2: Without looking at your code I would encourage you to get used to using the Type ahead feature of Eclipse. Type osti and then hit ctrl-space and you'll never get the capitalization or spelling of OSTimeDly wrong again. I use it for just about everything, sometimes I get to the last letter and then hit ctrl-space, i usually don't bother worrying about capitalization as ctrl-space doesn't care and will find all matches, when there's only one it will correct the capitalization and complete the entry.
HINT 3: use the auto-formatting (Source->Format) tool. I'm working with students and it's the first thing I do and then they immediately see their incorrectly nested structures. You can customize how the formatting looks with the Window>-Preferences->C/C++->Code Style.
Re: MOD54415 Compiler "undefined for this scope"
@tod, Dam, all these years using eclipse and did not know about those shortcuts. I guess i should spend more time learning the tool instead of trying to just write code twiddle leds 

Re: MOD54415 Compiler "undefined for this scope"
Tod, I totally agree with you on point 1. Gist is an awesome resource. I will still download and open, but hey I work here, so it's useful to see where people are having issues 
Points 2 and 3 would be very cool for me if I actually jumped up off the CLI. It's just that I like it down in here.

Points 2 and 3 would be very cool for me if I actually jumped up off the CLI. It's just that I like it down in here.
Dan Ciliske
Project Engineer
Netburner, Inc
Project Engineer
Netburner, Inc
-
- Posts: 192
- Joined: Mon Dec 17, 2012 6:24 am
Re: MOD54415 Compiler "undefined for this scope"
Well, I'm certainly glad to have those tips, and will do my best to remember them, although my company blocks a lot of websites, so I'll have to let them know so they can add it in so I can use it. For now, I'll just cut and paste code into this window instead. That out of the way, does anyone have an answer to my question?
Re: MOD54415 Compiler "undefined for this scope"
Sorry, your problem is due to "scoping". Let's take a look at what you're telling the compiler with regards to the 'upkt' variable.
In the function 'UdpReaderMain' you tell the compiler to create a symbol called 'upkt' which will represent a block of memory containing a UDPPacket, aka a variable. You have also told the compiler to allocate said block of memory on the Stack. Finally, because you created the declaration for 'upkt' inside the function that means the symbol 'upkt' is only in scope inside the function. Furthermore, since you did that inside the curly braces of the while loop, it is only in scope for that section of the function; it is not in scope for anything outside of it.
Right, so the reason why scope matters (besides keeping your breath from stinking...) is that once you are outside the scope where something was declared, the compiler treats the symbol as undefined, because it is. This is why you can have the same variable named used across multiple functions without it ever changing the data of one of the wrong ones; they're in different scopes.
Now, you eventually call DataHandler() from within the scope where 'upkt' was declared. Why isn't it in scope in the daughter call? Simply put, because DataHandler was not defined in the same scope. The compiler (rightfully so) doesn't believe that upkt exists when DataHandler is called. What if we call it from UserMain instead? How would/should it behave?
The solution is to pass 'upkt' as an argument to DataHandler, so that it is in scope of the function.
Did this help?
In the function 'UdpReaderMain' you tell the compiler to create a symbol called 'upkt' which will represent a block of memory containing a UDPPacket, aka a variable. You have also told the compiler to allocate said block of memory on the Stack. Finally, because you created the declaration for 'upkt' inside the function that means the symbol 'upkt' is only in scope inside the function. Furthermore, since you did that inside the curly braces of the while loop, it is only in scope for that section of the function; it is not in scope for anything outside of it.
Right, so the reason why scope matters (besides keeping your breath from stinking...) is that once you are outside the scope where something was declared, the compiler treats the symbol as undefined, because it is. This is why you can have the same variable named used across multiple functions without it ever changing the data of one of the wrong ones; they're in different scopes.
Now, you eventually call DataHandler() from within the scope where 'upkt' was declared. Why isn't it in scope in the daughter call? Simply put, because DataHandler was not defined in the same scope. The compiler (rightfully so) doesn't believe that upkt exists when DataHandler is called. What if we call it from UserMain instead? How would/should it behave?
The solution is to pass 'upkt' as an argument to DataHandler, so that it is in scope of the function.
Did this help?
Dan Ciliske
Project Engineer
Netburner, Inc
Project Engineer
Netburner, Inc