The Artima Developer Community
Sponsored Link

Weblogs Forum
Watch those spaces!

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Matthew Wilson

Posts: 145
Nickname: bigboy
Registered: Jun, 2004

Watch those spaces! (View in Weblogs)
Posted: Sep 21, 2008 2:36 PM
Reply to this message Reply
Summary
Having the computer help you write and maintain your code is an essential facet of successful software development, and all good consultants will recommended that you follow suit. (Even if, sometimes, they forget to do so themselves ...)
Advertisement

I'm always banging on to clients about the importance of periodically running code cleanup scripts over their code bases. One of the ones I recommended is a trailing spaces remover, essential for C/C++ code because of the dangerous effects it has on macros, and the concomitant difficulty of finding the problem(s). And yesterday I got caught by just such a situation, having failed to follow my own advice.

I'm in the process of adding some final touches to Pantheios before its (highly overdue) final 1.0 non-beta release. One of these is adding some examples illustrating how log statements may be targeted at certain back-ends by using the facilities for "overloading" the severity levels, i.e. combining a bona-fide severity level with additional information that may be used by a multiplexing/composite back-end to route the statement to specific concrete back-end(s). The details of what this all mean are somewhat outside this discussion, so suffice to say that it's the difference between, say

  #include <pantheios/pan.hpp> // gives us the 'pan' namespace alias, for brevity

  std::string general("general");

  pantheios::log(pan::notice, "A statement of ", general, " importance");
which is a candidate to be output by all back-ends (such as file, debugger, console, Syslog, ...), and, say
  #include <pantheios/pan.hpp> // gives us the 'pan' namespace alias, for brevity

  int beidSpecial = . . . // The identifier of the specific back-end to which the statement will be targetted

  std::string specific("specific");

  pantheios::log(pan::notice(beidSpecial), "A statement of ", specific, " importance");

These facilities have been available for the library for a very long-time, at least a year or so. But in writing the tutorial it became clear to me that users who're employing Pantheios in their C programs are somewhat left out in this regard. So I added the PANTHEIOS_MAKE_EXTENDED_SEVERITY() macro"

#define PANTHEIOS_MAKE_EXTENDED_SEVERITY(sev, xi28)   \
                                                      \
    (((sev) & 0x0f) | (((xi28) << 4) & ~0x0f))
Looks ok, yes? Except that I was on the receiving end of a brace of totally weird compiler errors, such as the following (from VC++ 9 x64):
H:\freelibs\pantheios\current\include\pantheios/pantheios.h(557) : error C2143: syntax error : missing ')' before '&'
H:\freelibs\pantheios\current\include\pantheios/pantheios.h(557) : error C2059: syntax error : ')'

I'm embarassed to admit that I had to sleep on this one before I had the mental wherewithall to realise my mistake, and to cause the IDE to show spaces. In that case the macro definition actually looks like the following (with the symbol « used to represent a space):

#define«PANTHEIOS_MAKE_EXTENDED_SEVERITY(sev,«xi28)«««\«««
««««««««««««««««««««««««««««««««««««««««««««««««««««««\
««««(((sev)«&«0x0f)«|«(((xi28)«<<«4)«&«~0x0f))

So, take the advice, as I will myself try to do more thoroughly, and strip those trailing spaces. I use a simple Perl script which is executed either by find (on UNIX) or for on Windows.

I'd love to hear from anyone who's had similar experiences, especially where they involve a little humbling stupidity. ;-)

Topic: PyCon Brazil Previous Topic   Next Topic Topic: The Next Phase of the Internet

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use