Judul : A stronger C/C++ Preprocessor
link : A stronger C/C++ Preprocessor
A stronger C/C++ Preprocessor
Ever felt you needed some preprocessing to generate some C/C++ code for you, but the C preprocesssor is too lacking? Say for example you wanted to include part of another file, or include output from an application. Perhaps the compile should be based on some data found on a remote server? Well, there are stronger preprocessors which work for C/C++, such as PHP.Here's an example:
/tmp> php test.cpp.php | g++ -x c++ -Wall -o test -Here's a more interesting example:
/tmp> ./test
Hello 0
Hello 1
Hello 2
Hello 3
Hello 4
/tmp> cat test.cpp.php
#include <iostream>
int main()
{
<?php for ($i = 0; $i < 5; ++$i) { echo 'std::cout << "Hello ', $i, '" << std::endl;'; } ?>
return(0);
}
/tmp>
/tmp> php weather_example.c.php | gcc -x c -Wall -o weather_example -
/tmp> ./weather_example
Hi, when I was compiled, the weather here in New York City was 57F
/tmp> cat weather_example.c.php
<?php
$w = file_get_contents('http://www.google.com/ig/api?weather=New+York+City');
$f = '<temp_f data="';
echo '#define __WEATHER__ ', (int)substr($w, strpos($w, $f)+strlen($f)), 'U', "\n";
?>
#include <stdio.h>
int main()
{
printf("Hi, when I was compiled, the weather here in New York City was %uF\n", __WEATHER__);
return(0);
}
/tmp>
Demikianlah Artikel A stronger C/C++ Preprocessor
Sekianlah artikel A stronger C/C++ Preprocessor kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.
Anda sekarang membaca artikel A stronger C/C++ Preprocessor dengan alamat link https://jendeladuniainternet.blogspot.com/2011/10/a-stronger-cc-preprocessor.html
0 Response to "A stronger C/C++ Preprocessor"
Posting Komentar