2

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?

Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
Muthu Ganapathy Nathan
  • 3,199
  • 16
  • 47
  • 77

3 Answers3

2

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.)

Fred Foo
  • 355,277
  • 75
  • 744
  • 836
  • ya, the conversion is implicit.And my doubt is whether the compiler generates a implicitly converted code before creating any object program OR it does the implicit conversion operation line by line( during object code creation of each line.) – Muthu Ganapathy Nathan Aug 04 '11 at 19:03
  • @EAGER_STUDENT: I'm not sure what you mean, but the way the compiler performs the conversion is its choice; the C standard only guarantees the resulting *behavior*. In any case, the addition of a `const` qualifier will most likely not produce different object code, since it's a compile-time construct. – Fred Foo Aug 04 '11 at 19:05
1

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.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • I like your explanation very much. Just to clarify, Frama-C does not have `double x = (double)n;` textually in memory any more than a compiler does. It has an Abstract Syntax Tree in which the conversion is made explicit (as most compilers probably do, because the standard says that's what `x=n;` means). The conversion is only shown textually if you ask for the AST to be pretty-printed (say, as an help to debugging). – Pascal Cuoq Aug 04 '11 at 22:45
1

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.

Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281