structure Already Declared -- Where?

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

structure Already Declared -- Where?

Post 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)
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: structure Already Declared -- Where?

Post 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)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: structure Already Declared -- Where?

Post 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
BERESHEIT
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: structure Already Declared -- Where?

Post 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.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: structure Already Declared -- Where?

Post 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.
sorry for my bad english
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: structure Already Declared -- Where?

Post by Fred »

It's not a problem, it's an improvement request and I think it's perfectly valid.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: structure Already Declared -- Where?

Post 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.
quidquid Latine dictum sit altum videtur
Post Reply