Search code examples
ccompiler-constructionimplicit-conversionframa-c

Whether Compiler generates a Implicitly converted code before creating an object code?


I installed frama-c in my system.

What it does it, it converts all my code into more expanded form with all the implicit conversions of C..

(E.g)
//My Actual Code

 if(opTab ==NULL || symTab ==NULL || intermediateFile==NULL || sourceCode ==NULL)
 {
   printf("\nError in opening file streams");
   exit(EXIT_FAILURE);
 }

//Frama-c converted code

 if (opTab == (void *)0) {
    printf((char const   *)"\nError in opening file streams");
    exit(1);
  }
  else {
    if (symTab == (void *)0) {
      printf((char const   *)"\nError in opening file streams");
      exit(1);
    }
    else {
      if (intermediateFile == (void *)0) {
        printf((char const   *)"\nError in opening file streams");
        exit(1);
      }
      else {
        if (sourceCode == (void *)0) {
          printf((char const   *)"\nError in opening file streams");
          exit(1);
        }
      }
    }
  }

Now my doubt is , Before creating an object program, whether C compiler do all implicit convertions?

OR

whether during creation of object program , these implicit conversions is done in parallelly?

OR

It is implementation dependent? If so, why?


Solution

  • Most likely not. I'm not familiar with frama-c, but the conversion you're seeing is source-to-source -- i.e., it takes C source as input and gives you modified C source as output. Apparently its job is to make the code more explicit and verbose.

    A C compiler typically wouldn't perform that kind of source conversion. (Well, the preprocessor does, but that's different.)

    It will generate code to perform whatever conversions are needed, but it will do so in the form of either machine language, or assembly language, or some intermediate form.

    To take a simple example, this:

    int n = 42;
    double x = n;
    

    performs an implicit conversion from int to double on the initialization of x, but probably nothing in the compilation process is going to create text that looks like

    double x = (double)n;
    

    C compilers take C source code as input. They don't generally generate it as output. In theory they could, but there's no reason for them to do so.