gcc8

How to get the structure field data type in the GCC compiler source code and modify it?


If I have such a structure:

struct test{
   float c,
         f,
         ops;
};

How can I modify the GCC compiler source code to make it as follows:

struct test{
  double c,
         f,
         ops;
};

I now have such a requirement, I need to modify the gcc source code so that when he compiles a structure of a certain mode, he changes its type to a specified type.

Thank you!


Solution

  • your goal is very ambitious!

    A possible approach could be to develop your own GCC plugin doing that job.

    My recommendations:

    If your code base is in C, consider using Frama-C (or Clang) and design your tool as a C to C transpiler.

    Perhaps clever preprocessor tricks like #define float double followed by #undef float might be enough.