[Qgis-developer] Revision 5269 - qgsgeometry.cpp Compilation Error

Peter Ersts ersts at amnh.org
Wed Apr 12 17:42:04 EDT 2006


Marco,

The use of brakets in case statements did vary with compiler versions, 
by that was many moons ago something around version 2.5 I believe. 
Declaring a variable in a case statement without brakets should be 
illegal no matter what because the scope is ambiguous, but it 
interesting becuase it compiled just fine yesterday (April 11) on the 
same machine without any problems, but I don't remember the exact 
revision, sorry.

Thanks
-pete

If it helps, I am using gcc (GCC) 4.0.3 (Debian 4.0.3-1)



nhugent at hispeed.ch wrote:

>Hi Peter,
>
>It seems to  compile on my system even without the brakets. Perhaps different compiler version.
>I'll commit the brackets in a few minutes.
>
>Marco
>
>
>  
>
>>Got this error this morning (April 12) while trying a fresh build of 
>>Revision 5269:
>>
>>qgsgeometry.cpp: In member function 'QgsPoint QgsGeometry::closestSegmentWithContext(QgsPoint&, QgsGeometryVertexIndex&,double&)':
>>qgsgeometry.cpp:993: error: jump to case label
>>qgsgeometry.cpp:949: error:   crosses initialization of 'int* npoints'
>>qgsgeometry.cpp:948: error:   crosses initialization of 'unsigned char* ptr'
>>make[4]: *** [libqgis_core_la-qgsgeometry.lo] Error 1
>>
>>
>>It is easily fixed by placing {} around the case statements for the switch() that starts on line 940 of qgsgeometry.cpp.
>>
>>switch() 
>>{
>> case 1:
>> {
>>   blah blah
>> }
>> case 2:
>> {
>>   blah blah
>> }
>>}
>>
>>
>>I apologize for posting this to the list and not putting on trac but I am slowly working my way through all of the documentation for everything.  Below is the a modification for the switch() statement starting on line 940 the compiled correctly for me.
>>
>>   switch (wkbType)
>>   {
>>   case QGis::WKBPoint:
>>     {
>>       // Points have no lines
>>       return QgsPoint(0,0);
>>     }
>>   case QGis::WKBLineString:
>>     {
>>       closestSegmentIndex = 0;
>>       unsigned char* ptr = mGeometry + 5;
>>       int* npoints = (int*) ptr;
>>       ptr += sizeof(int);
>>       for (int index=0; index < *npoints; ++index)
>>       {
>>         if (index > 0)
>>         {
>>           prevx = thisx;
>>           prevy = thisy;
>>         }
>>
>>         thisx = (double*) ptr;
>>         ptr += sizeof(double);
>>         thisy = (double*) ptr;
>>
>>         if (index > 0)
>>         {
>>           if (
>>                (
>>                  testdist = distanceSquaredPointToSegment(point,
>>                                                           prevx, prevy,
>>                                                           thisx, thisy,
>>                                                           minDistPoint) 
>>// TODO: save minDistPoint into something meaningful.
>>                )
>>                < sqrDist )
>>           {
>>#ifdef QGISDEBUG
>>//      std::cout << "QgsGeometry::closestSegment: testDist "
>>//                << testdist << ", sqrDist"
>>//                << sqrDist
>>//                << "." << std::endl;
>>#endif
>>             closestSegmentIndex = index;
>>             sqrDist = testdist;
>>           }
>>         }
>>
>>         ptr += sizeof(double);
>>       }
>>
>>       beforeVertex.push_back(closestSegmentIndex);
>>
>>       break;
>>
>>       //todo: add wkb parsing
>>     }
>>   case QGis::WKBPolygon:
>>     {
>>	break;
>>     }
>>   } // switch (wkbType)
>>
>>
>>
>>
>>-- 
>>====================================
>>Peter J. Ersts, Project Specialist
>>American Museum of Natural History
>>Center for Biodiversity and Conservation
>>Central Park West at 79th Street
>>New York, New York 10024
>>Tel: (212)-496-3488 or (212)-769-5742
>>Fax: (212)-313-7295 or (212)-769-5292
>>Web: http://cbc.amnh.org
>>
>>Visit the Indo-South Atlantic Consortium on Humpback Whales 
>>Web:  http://www.isach.org
>>
>>_______________________________________________
>>Qgis-developer mailing list
>>Qgis-developer at lists.qgis.org
>>http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-developer
>>
>>
>>    
>>


-- 
====================================
Peter J. Ersts, Project Specialist
American Museum of Natural History
Center for Biodiversity and Conservation
Central Park West at 79th Street
New York, New York 10024
Tel: (212)-496-3488 or (212)-769-5742
Fax: (212)-313-7295 or (212)-769-5292
Web: http://cbc.amnh.org

Visit the Indo-South Atlantic Consortium on Humpback Whales Web: http://www.isach.org




More information about the Qgis-developer mailing list