Question

I'm surprised that Eclipse can fail to run the simplest program in not only one way but in many way at the same time. The program is

#include <stdio.h>
int main ()
{
  int  n; 
  while (scanf("%d", &n) > 0)
  {
    printf("%d\n", n);
  }
  return 0;
}

Failure 1: When run in the simulator the output is displayed twice for no reason. The output should be displayed once.

Failure 2: When run with the DE2 board then output is not displayed at all.

Why can't my environment perform like it should?

Was it helpful?

Solution

Since you don't give many details I'm just guessing:

  1. there could be some kind of echoing enabled

  2. on embedded systems <stdio.h> is not required to be supported. <stdio.h> is guaranteed to be available only in hosted environments (i.e. under control of an OS), not in freestanding environments (bare metal).

Quoting from the C99 draft standard N1256:

4. Conformance

[...]

6

The two forms of conforming implementation are hosted and freestanding. A conforming hosted implementation shall accept any strictly conforming program. A conforming freestanding implementation shall accept any strictly conforming program that does not use complex types and in which the use of the features specified in the library clause (clause 7) is confined to the contents of the standard headers <float.h>, <iso646.h>, <limits.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, and <stdint.h>. A conforming implementation may have extensions (including additional library functions), provided they do not alter the behavior of any strictly conforming program.

You should check the documentation of the compiler for your board to see which headers it supports.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top