Menu

Compiling legacy C code

2009-08-06
2012-09-26
  • Danilo J Bonsignore

    I remember updating all old style C function declaration when I compiled with VC and then djgpp, from idiom void f(a) int a; {...} to standard void f(int a) {}. Now I used the CPP to output a clean, no preprocessor, file from f.c to f.cpp, but, it would not accept the old style declaration. Already tried different combinations of -std= and -x without success... but changing the file termination from .cpp to .c makes it compilable. Since I am using the CPP to produce the no-headers version, I need to rename .c to .c.orig then the newly generated .cpp to .c.

    So... how do I make the IDE to select .c compilation even if the file has termination .cpp so it accepts ?

     
    • cpns

      cpns - 2009-08-10

      > I find no way to tell the IDE to make: .c to .i AND .i to .o BUT NOT .c to .o.

      Create a custom rule, or use custom build rules for each file individually. If you ar eperform this operation on all files, use the first, if just a few use the second.

      You create custom rules in a text file using GNU make syntax, and then add the file as an make 'include' file in the project options.

      > disable the IDE usefulness in one way or another!
      Yes, maybe, but it works for the general case, for reasons best known to yourself, you want to make things complicated. I think you'd be hard pushed to find an IDE that would directly support your requirements. And since few would ever require this functionality, it is unlikely that such an enhancement will be implemented unless you do it yourself. There are far more glaring omissions from Dev-C++ that effect everybody (crab debug interface, no support for multiple build configurations, no support for multiple projects to name just a few)..

      If this is still related to your attempt to build Nethack, you really are doing it the hard way, and I do not believe that this approach is either necessary nor particularly productive.

       
    • cpns

      cpns - 2009-08-06

      .cpp is the conventional file extension for a C++ source file. When presented with such a file, most compilers (including GCC) will switch to C++ compilation.

      The use of the extension .i is specifically recognised by the compiler as a C source file that must not be pre-processed, so I suggest that you use that. Other extensions recognised by the compiler for specific purposes are described at http://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Overall-Options.html

      Clifford

       
    • cpns

      cpns - 2009-08-06
       
    • cpns

      cpns - 2009-08-06

      You can also use

      -x c

      as a compiler option to force C compilation regardless of extension.

      or

      -x cpp-output

      to specify C compilation without pre-processing (which you have already done).

      Clifford

       
    • Danilo J Bonsignore

      The .i extension solves the compilation problem calling the right compiler, but telling the IDE to pipe the two file types included as files in the project finds more than one contradiction. I find no way to tell the IDE to make: .c to .i AND .i to .o BUT NOT .c to .o. Several combinations of include add make file, include file in compilation, custom make command, use custom makefile instead disable the IDE usefulness in one way or another! Particularly there seems to be no way to have both .c and .i versions in the project s file list so to edit in the .c AND inspect the .i because adding the .c file automatically adds a .o target to the makefile.win file... So how can you place an intermediate target between .c and .o while using the IDE facilities? In general it would be desirable to make explicit a general method to make the IDE process the string .a(c-tool).b(c-tool-2).c(c-tool-3)...(c-tool-n).o(linker).exe where c-tool turns one extension type into another extension type (despite the automatic targeting of .c into .o) (Note that exposing the problem itself is a problem because the problem is an inconsistency in the IDE treatment of file types)....

       

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.