Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compile a stream of data in C?

Is it possible to compile a stream of data rather than compiling a .c file using gcc? for example, is it possible that instead of having my code stored in any xyz.c file, I can directly compile the code?

like image 442
Kazekage Gaara Avatar asked Jul 07 '11 14:07

Kazekage Gaara


People also ask

What is data stream in C?

Conceptually, the C program deals with a stream instead of directly with a file. A stream is an idealized flow of data to which the actual input or output is mapped. That means various kinds of input with differing properties are represented by streams with more uniform properties.

Which function links a stream to a file?

Having created a stream, we can connect it to a file using the member function "open(...)".

What is stream file?

A file stream is a sequence of bytes used to hold file data. Usually a file has only one file stream, namely the file's default data stream. However, on file systems that support multiple data streams, each file can have multiple file streams. One of these is the default data stream, which is unnamed.


2 Answers

Use gcc options -x and -

$ echo -e '#include <stdio.h>\nmain(){puts("Hello world");return 0;}' | gcc -xc -ogarbage - && ./garbage && rm garbage
Hello world

The single line command above is made up of the following parts:

echo -e '#include <stdio.h>\nmain(){puts("Hello world");return 0;}' # "source"
|                                                                   # pipe
gcc -xc -ogarbage -                                                 # compile
&&                                                                  # and
./garbage                                                           # run
&&                                                                  # and
rm garbage                                                          # delete
like image 177
pmg Avatar answered Sep 17 '22 15:09

pmg


This may answer you question, though it is rarely useful.

like image 28
ShinTakezou Avatar answered Sep 16 '22 15:09

ShinTakezou