Page 1 of 1

structure Already Declared -- Where?

Posted: Sun Jan 20, 2013 9:34 pm
by jassing
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)

Re: structure Already Declared -- Where?

Posted: Mon Jan 21, 2013 1:12 am
by IdeasVacuum
+1 (On Windows, it is often as not an API structure that previously needed to be defined in PB but does not now)

Re: structure Already Declared -- Where?

Posted: Mon Jan 21, 2013 1:26 am
by netmaestro
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

Re: structure Already Declared -- Where?

Posted: Mon Jan 21, 2013 9:06 am
by jassing
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"

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?

Posted: Mon Jan 21, 2013 4:30 pm
by Josh
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.

Re: structure Already Declared -- Where?

Posted: Mon Jan 21, 2013 4:51 pm
by Fred
It's not a problem, it's an improvement request and I think it's perfectly valid.

Re: structure Already Declared -- Where?

Posted: Mon Jan 21, 2013 6:19 pm
by freak
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.