structure Already Declared -- Where?
structure Already Declared -- Where?
It would be nice, instead of just the "this structure is already declared" error -- it tells us where that procedure was already declared... (ditto for other 'already declared' errors)
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: structure Already Declared -- Where?
+1 (On Windows, it is often as not an API structure that previously needed to be defined in PB but does not now)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: structure Already Declared -- Where?
I have this in my templates list called 'structure block', it makes it quick and painless to use this recommended (by me) code for all api structures that aren't currently defined natively in PB:
Code: Select all
CompilerIf Defined(, #PB_Structure) = #False
Structure
EndStructure
CompilerEndIf
BERESHEIT
Re: structure Already Declared -- Where?
Right we can work around everything...
the point is the compiler knows it was created already -- so just say "in file1.pbi line 301"
It's happened with structures, lists, procedures -- it'd just be nice if it were a bit more helpful...
With procedures, it's easy -- just double click on the error line & it takes you to where (at least one) was already defined.
I don't know about you -- but it would be fairly ugly code to wrap everything in compilerif's.
more importantly, as IdeasVacuum pointed out - let's say you have wrapped all your structures up "just in case"
And your program works fine with PB5.1 beta4, but then beta5 comes out, and it has a structure "winlink" now your program is broken, but you have to hunt for the 'why'.
It would be much easier to not have it wrapped, get an error and be told where it was already created...
This issue gets bigger when you're not the only one working on a single project... I may create a structure "jFishes" and work in my module happily. Another programmer working on a different module, also creates a structure "JFIshes" and his works perfectly well in testing.
But then come to compile the actual application, and now, "What? how can that be" -- and now a search is on. In either cases, being told where it was previously defined makes debugging much easier.
Think about driving to someone's house in a city you've never been, it's dark out you're lost, so you ask "Hey, I'm headed for <this address>" the response you get from helpful person "you're not there, you're here" and they walk away... That's what the compiler does "already defined" and walks away.
the point is the compiler knows it was created already -- so just say "in file1.pbi line 301"
It's happened with structures, lists, procedures -- it'd just be nice if it were a bit more helpful...
With procedures, it's easy -- just double click on the error line & it takes you to where (at least one) was already defined.
I don't know about you -- but it would be fairly ugly code to wrap everything in compilerif's.
more importantly, as IdeasVacuum pointed out - let's say you have wrapped all your structures up "just in case"
Code: Select all
compilerif defined(winlink,#pb_structure) = #false
structure winlink
... blah ..
endstructure
compilerendif
And your program works fine with PB5.1 beta4, but then beta5 comes out, and it has a structure "winlink" now your program is broken, but you have to hunt for the 'why'.
It would be much easier to not have it wrapped, get an error and be told where it was already created...
This issue gets bigger when you're not the only one working on a single project... I may create a structure "jFishes" and work in my module happily. Another programmer working on a different module, also creates a structure "JFIshes" and his works perfectly well in testing.
But then come to compile the actual application, and now, "What? how can that be" -- and now a search is on. In either cases, being told where it was previously defined makes debugging much easier.
Think about driving to someone's house in a city you've never been, it's dark out you're lost, so you ask "Hey, I'm headed for <this address>" the response you get from helpful person "you're not there, you're here" and they walk away... That's what the compiler does "already defined" and walks away.
Re: structure Already Declared -- Where?
I think also, it's better to have a crash if a structure is defined twice. If I'm protecting my structures with 'defined', i can have bad mistakes and a lot of work to find the bug.
But I don't understand the topic problem. With Edit > Find in Files I check my project in few seconds.
But I don't understand the topic problem. With Edit > Find in Files I check my project in few seconds.
sorry for my bad english
Re: structure Already Declared -- Where?
It's not a problem, it's an improvement request and I think it's perfectly valid.
Re: structure Already Declared -- Where?
Meanwhile, a simple solution to find the previous declaration is to just add another declaration as the first line of the main source file. This way the previous first declaration is now also the second one and will cause an error.
Unless of course the first declaration is in a resident. Then you will get again the error on this new declaration.
Unless of course the first declaration is in a resident. Then you will get again the error on this new declaration.
quidquid Latine dictum sit altum videtur