开发者

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?


The first argument to printf is of type const char*, so if you included <stdio.h> as you should before using printf, the conversion will be performed implicitly by the compiler. (I.e., there's no need for the cast in this case.)


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.


I am one of the Frama-C developers.

What you are seeing is really a textual representation of the Abstract Syntax Tree that happens to be compilable C code. As you noticed, a lot of conversions are made explicit. As far as we know and with the possibility of bugs having crept in, adding these conversions does not change the meaning of the program because these conversions are those that the compiler would have made anyway according to section 6.3 of the C99 standard (especially 6.3.1.8 "Usual arithmetic conversions").

If the pretty-printed code, once compiled, gives different results from the original, this is a bug that you can report on the Frama-C bug tracker.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜