Loading ...
Sorry, an error occurred while loading the content.
 

C coding practices that are problematic on certain C compilers

Expand Messages
  • Steve Grubb
    Hi, Jeffrey Hutzelman pointed out recently that a coding practice that I used widely in code rewrite/cleanup for ploticus 2.40 is not proper practice and will
    Message 1 of 1 , Apr 2, 2008
      Hi, 

      Jeffrey Hutzelman pointed out recently that a coding practice that I used widely in code rewrite/cleanup for ploticus 2.40 is not proper practice and will cause problems when building with certain C compilers (in his case, Sun Solaris C compiler).

      With gcc (at least 3.1 and earlier) which I use, everything seems to work fine.

      Jeffrey supplied a patch which is available via http://ploticus.sourceforge.net/doc/news.html

      For those interested in the details, please see below.

      -Steve

      ---------- Forwarded message ----------
      From: Jeffrey Hutzelman <jhutz@...>
      Date: Fri, Mar 28, 2008 at 11:27 AM
      Subject: Re: Ploticus bug - comparison to ""
      To: stevegrubb@...


      I suspect that gcc's default behavior is to coalesce identical literal strings to save space.  If so, you likely wouldn't notice a problem in most of the cases I saw.  We built using gcc on several x86 platforms and saw no problem.  But we generally make a habit of using Sun's compiler on Solaris, and it seems to optimize differently.

      --Jeff

      -----Original Message-----
      From: "Steve Grubb" <stevegrubb@...>
      Date: Friday, Mar 28, 2008 9:02 am
      Subject: Re: Ploticus bug - comparison to ""
      To: "Jeffrey Hutzelman" <jhutz@...>

      Jeffrey,  thanks for alerting me to my muddled thinking.....
      >
      >I guess I got away with it because a lot of these variables are initialized using eg. labels = '';
      >
      >then the comparison   if( labels != '' )  is true if the variable is no longer in its initialized state.
      >(However if labels gets set to a non-constant '' you're right the comparison wouldn't be valid).
      >
      >It's kind of a wonder that 2.4 passed QA via the gallery and test suite here on my solaris / gcc 3.1
      >
      >Certainly not best practice!  I'll clean this up for the next release.  and look more into your specific issue w/ labelfmtstring soon.
      >
      >Thanks again,
      >
      >-Steve
      >
      >
      >On Thu, Mar 27, 2008 at 6:33 PM, Jeffrey Hutzelman <jhutz@...> wrote:
      >
      > A construct like
      >
      >  if (labels != '')
      >
      > does not do anything useful in C, because it compares the pointers rather
      > than the strings to which they point.  I found numerous comparisons like
      > this in Ploticus 2.40, and have attached a patch which fixes them.
      >
      > For me, this manifested itself as the pie prefab's labelfmtstring
      > parameter not having any effect on SPARC Solaris 9 (using plpng compiled
      > with the Sun Forte 7 compiler).  For completeness, I've attached a sample
      > data file and the output produced by builds of Ploticus 2.40 with and
      > without my patch.  Both graphs were produced using this command:
      >
      > pl -png -o stdout -prefab pie data=/tmp/rd 'center=3 2.2' radius=1.5 \
      >  colorfld=1 values=2 'labelfmtstring=@3 (@PCT%)' labelfarout=1.1
      >
      >-- Jeffrey T. Hutzelman (N3NHS) <jhutz+@...>
      >   Sr. Research Systems Programmer
      >   School of Computer Science - Research Computing Facility
      >   Carnegie Mellon University - Pittsburgh, PA
      >
      >


    Your message has been successfully submitted and would be delivered to recipients shortly.