C - Print to screen without #include <stdio.h>?

Is there a way to print the C source file on the screen without including <stdio.h> ?

Here is my situation: I was asked to programmatically process 1000 C source files, each of which will implement several numerical functions in C (these functions should work with data in memory , regardless of I / O). The origin of these source files is unclear, and therefore, I would like to make sure that my computer will not be harmful when compiling and running these source files.

Is there a way to find out if the C source file is potentially dangerous? I was thinking of asking developers to avoid any #include statements, but I only need printf - since I would like them to include the output of their calculations within main() .

Any ideas?

+4
source share
6 answers

Of course, add a prototype for printf to the top of the source file, if you are linking to CRT libraries, you can use this function without including stdio.h

printf prototype

 int printf ( const char * format, ... ); 
+3
source

Is there a way to find out if the C source file is potentially dangerous?

No no. Perhaps the malicious source file can do whatever it wants by defining its own prototypes or using the built-in assembly - #include is just a compilation convenience.

+3
source

There are, although they are probably slightly larger than the size of the SO format. You mainly use assembly calls in C. The KSplice blog covers the topic (with code and examples) here .

+1
source

I would like to clarify why we need printf and studio.h to make the concept more understandable. C is a portable language. You can compile c for Linux, Mac OSX, Windows. In each one that causes the output, it usually comes down to a system call or in embedded systems, working directly with the frame buffer or Uart device.

So, of course, maybe you want to do this? Depends why. If you are coding a specific platform and do not have printf (), you may have to consider calling a system call directly for that platform / writing specific assembly code for a specific platform. It all depends on your use case.

+1
source

Of course, put the necessary function prototypes in your program.

If you mean that you are not using printf, you have several options: you can use fwrite or you can do without streams and use write, or you can directly refer to the input / output services of the operating system, or maybe you can talk to the display hardware directly or more.

If you need a better answer, please explain why you do not want to include stdio.h

0
source

This is stupid, but still:

 #include <string.h> int main() { puts ("hi"); return 0; } 

and conclusion:

 $ gcc -o try try.c $ ./try hi 
0
source

All Articles