How to check that a type double is not being used in the code.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dissectcode2
    New Member
    • Apr 2009
    • 32

    How to check that a type double is not being used in the code.

    Hi - Is there a way to make gcc compilation fail or how can I write a script to check that double types are not being used in the C code?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Write code to read the source code and scan for the word double. You will need to record the include file names and search those as well.

    Comment

    • dissectcode2
      New Member
      • Apr 2009
      • 32

      #3
      Originally posted by weaknessforcats
      Write code to read the source code and scan for the word double. You will need to record the include file names and search those as well.
      That is a beautiful idea - how in C does one scan an entire set of 500 files for one keyword. And then...how can I turn the results into a "warning" ?

      thank you

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Your scanning code becomes a pre-condition for the build. That is, launch your gcc build from the scan code. That way you can produce warnings from your code before doing the gcc build.

        I expect there are gcc tools in place already. That is, Visual Studio.NET has a pre-condition and a post-condittion for its project builds where the pre-condition steps are executed before the build and the post-condition steps after the build. The project user just clicks "build" as usual and these additional steps become part of the overall build process for that project.

        As to scanning 500 files, I would put those filenames in a disc file and direct the scan code to scan every file whose filename is in that file. If you are using hand-written make files, you could first scan the make file for the files to be compiled and scan those.

        Further, you could have a second file of keywords so the scan code can search for many keywords as once. I might even add a qualifier for must be absent and one for must be present.

        In effect you are writing your own pre-processor. This is exactly what Oracle does with their pro*C. You put Oracle keywords in your code and this scanner comes along and changes those keyowrds to the actual C code that needs to be there. That expanded file is then the one sent to the C pre-processor, which further expands the C macros and passes the thing along to the compiler. That way you can connect to an Oracle database without needing to know anything about how to do that. You just use the pro*C word instead.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          How about a file that includes all the other files and defines the following first:

          Code:
          #define double YOOHOO_DOUBLE_USED!
          kind regards,

          Jos

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            Yep. Gotta scan for double there also.

            Comment

            Working...