Menu

problem with included header file

Manuel
2008-11-09
2013-04-26
  • Manuel

    Manuel - 2008-11-09

    Hi Mike,

    First all, let me say thanks for your work on the LZZ tool. It's a great idea and for what I've seen so far seems to be neatly implemented.

    I've only encountered a little problem. I have the following file Test.lzz:

    // Test.lzz
    #include "Foo.h"

    class Test
    {  
       Foo::Bar x;
    };

    And Foo.h in the same directory:

    class Foo
    {
    public:
           typedef int Bar;
    };

    Then I run "lzz Test.lzz" and everything goes right, except that in the Test.h file that's generated, I don't get  #include "Foo.h" which I would need as I'm using the definiton of Foo (to access the typedef).

    Regards,
    Manuel

     
    • Mike Spencer

      Mike Spencer - 2008-11-09

      Manuel:

      When Lzz encounters a #include it just records the macros defined in the file.  Lzz does not output the #include directive in the generated h or cpp file.  Would actually be very hard for it to decide where best to place it .  Instead you must be explicit:

      #hdr
      // this code goes at the top of the header file, can be anything (but usually include directives)
      #end

      #src
      // this code goes at the top of the source file, can be anything
      #end

      You can place this code anywhere in the lzz file, even at the bottom of the file.  So, for example:

      // Test.lzz

      class Test
      {  
         Foo::Bar x;
      }

      #hdr
      #include "Foo.h"
      #end

      Note Lzz just copies text between #hdr .. #end to the header file.  So in here it does not process #include files.

      You'll only want Lzz to read #include files if you use macros.  For example:

      // Test.lzz
      #include "project.h"

      UTIL_BEG

      std::string trim () { ... }

      UTIL_END

      Here, UTIL_BEG and UTIL_END might be the start and end of a namespace, something like

      // project.h

      #define UTIL_BEG namespace util {
      #define UTIL_END }

      But if you do this, you might find it cleaner to use the -a command line option:

      lzz -a project.h Test.lzz

      This does the same thing: lzz includes project.h at the top of your lzz file.

      Mike

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.