f



A program which would print out it's own source code - possible or not?

Is it possible to write a program which would print out it's own
source code, using C++?
0
mikhal80 (1)
1/23/2008 11:15:33 AM
comp.lang.c++ 49423 articles. 6 followers. Post Follow

32 Replies
420 Views

Similar Articles

[PageSpeed] 4

mikhal80@gmail.com wrote:
> Is it possible to write a program which would print out it's own
> source code, using C++?

Yes.

- Jensen
0
1/23/2008 11:26:51 AM
On 23 Jan, 11:15, mikha...@gmail.com wrote:
> Is it possible to write a program which would print out it's own
> source code, using C++?

Google "quine".
0
1/23/2008 11:59:52 AM
mikhal80@gmail.com wrote:
> Is it possible to write a program which would print out it's own
> source code, using C++?

yes, here is one example for free:
0
anon3413 (206)
1/23/2008 3:24:30 PM
On 2008-01-23 10:24:30 -0500, anon <anon@no.no> said:

> mikhal80@gmail.com wrote:
>> Is it possible to write a program which would print out it's own
>> source code, using C++?
> 
> yes, here is one example for free:

deep, philosophically...  lol.

-- 

-kira

0
Kira
1/23/2008 8:21:19 PM
Kira Yamato wrote:
> On 2008-01-23 10:24:30 -0500, anon <anon@no.no> said:
>
>> mikhal80@gmail.com wrote:
>>> Is it possible to write a program which would print out it's own
>>> source code, using C++?
>>
>> yes, here is one example for free:
>
> deep, philosophically...  lol.

It probably is.  But my dumb compiler complains that there is no
'main' in my program...

V
-- 
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask 


0
v.Abazarov (13256)
1/23/2008 8:22:31 PM
mikhal80@gmail.com writes:
> Is it possible to write a program which would print out it's own
> source code, using C++?

Yes, that's trivial.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Until real software engineering is developed, the next best practice
is to develop with a dynamic system that has extreme late binding in
all aspects. The first system to really do this in an important way
is Lisp. -- Alan Kay
0
pjb (7869)
1/23/2008 9:27:09 PM
"Victor Bazarov" <v.Abazarov@comAcast.net> writes:

> Kira Yamato wrote:
>> On 2008-01-23 10:24:30 -0500, anon <anon@no.no> said:
>>
>>> mikhal80@gmail.com wrote:
>>>> Is it possible to write a program which would print out it's own
>>>> source code, using C++?
>>>
>>> yes, here is one example for free:
>>
>> deep, philosophically...  lol.
>
> It probably is.  But my dumb compiler complains that there is no
> 'main' in my program...

Ok, so you need at least a main.

int main(){
    // add something here...
    return 0;
}


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Until real software engineering is developed, the next best practice
is to develop with a dynamic system that has extreme late binding in
all aspects. The first system to really do this in an important way
is Lisp. -- Alan Kay
0
pjb (7869)
1/23/2008 9:27:56 PM
Pascal Bourguignon wrote:
> "Victor Bazarov" <v.Abazarov@comAcast.net> writes:
>
>> Kira Yamato wrote:
>>> On 2008-01-23 10:24:30 -0500, anon <anon@no.no> said:
>>>
>>>> mikhal80@gmail.com wrote:
>>>>> Is it possible to write a program which would print out it's own
>>>>> source code, using C++?
>>>>
>>>> yes, here is one example for free:
>>>
>>> deep, philosophically...  lol.
>>
>> It probably is.  But my dumb compiler complains that there is no
>> 'main' in my program...
>
> Ok, so you need at least a main.
>
> int main(){
>    // add something here...
>    return 0;
> }

Weird.  This one doesn't print its own source code.  Why?

V
-- 
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask 


0
v.Abazarov (13256)
1/23/2008 9:32:12 PM
Victor Bazarov wrote:
> Kira Yamato wrote:
>> On 2008-01-23 10:24:30 -0500, anon <anon@no.no> said:
>>
>>> mikhal80@gmail.com wrote:
>>>> Is it possible to write a program which would print out it's own
>>>> source code, using C++?
>>>
>>> yes, here is one example for free:
>>
>> deep, philosophically...  lol.
>
> It probably is.  But my dumb compiler complains that there is no
> 'main' in my program...
>

But other compilers actually once compiled this, ran it, and produced 
an identical empty output.

This entry in the 1994 Obfuscated C contest won its class

http://www.ioccc.org/1994/smr.c
http://www.ioccc.org/1994/smr.hint


and changed the category into "Smallest, non-empty, self-replicating 
program".



Bo Persson


0
bop (1086)
1/23/2008 9:41:52 PM
Bo Persson wrote:
> Victor Bazarov wrote:
>> Kira Yamato wrote:
>>> On 2008-01-23 10:24:30 -0500, anon <anon@no.no> said:
>>>
>>>> mikhal80@gmail.com wrote:
>>>>> Is it possible to write a program which would print out it's own
>>>>> source code, using C++?
>>>>
>>>> yes, here is one example for free:
>>>
>>> deep, philosophically...  lol.
>>
>> It probably is.  But my dumb compiler complains that there is no
>> 'main' in my program...
>>
>
> But other compilers actually once compiled this, ran it, and produced
> an identical empty output.

Can you please state which compilers did (or do)?

> This entry in the 1994 Obfuscated C contest won its class
>
> http://www.ioccc.org/1994/smr.c
> http://www.ioccc.org/1994/smr.hint
>
>
> and changed the category into "Smallest, non-empty, self-replicating
> program".

V
-- 
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask 


0
v.Abazarov (13256)
1/23/2008 9:50:11 PM
On Jan 23, 11:15=A0am, mikha...@gmail.com wrote:
> Is it possible to write a program which would print out it's own
> source code, using C++?

Heres my effort FWIW. (BTW, if its a homework assigmment then I
wouldnt recommend handing the following in).

Also though it compiles in gcc 3.4 I don't know that the fstream
declaration in the for loop is actually legal. I have a funny idea it
isnt for some reason...

#include <fstream>
#include <string>
#include <cassert>
#include <iostream>

template <typename T1, typename T2>
inline
void apply(T1* f,T2 & out)
{
  std::string str;
  for(
   std::ifstream in(f);
     getline(in,str);
       out << str <<'\n'
  ){}
}


int main()
{
 apply(__FILE__,std::cout);

}

regards
Andy Little







0
andy199 (808)
1/23/2008 10:45:36 PM
Victor Bazarov wrote:
> Pascal Bourguignon wrote:
>> "Victor Bazarov" <v.Abazarov@comAcast.net> writes:
>>
>>> Kira Yamato wrote:
>>>> On 2008-01-23 10:24:30 -0500, anon <anon@no.no> said:
>>>>
>>>>> mikhal80@gmail.com wrote:
>>>>>> Is it possible to write a program which would print out it's own
>>>>>> source code, using C++?
>>>>> yes, here is one example for free:
>>>> deep, philosophically...  lol.
>>> It probably is.  But my dumb compiler complains that there is no
>>> 'main' in my program...
>> Ok, so you need at least a main.
>>
>> int main(){
>>    // add something here...
>>    return 0;
>> }
> 
> Weird.  This one doesn't print its own source code.  Why?
> 
> V

Allow me to correct Pascal's code:

int main()
{
    // add something here to print its own source.
    // this is left as an exercise to the reader
    return 0;
}

0
no.spam9 (2339)
1/23/2008 11:19:58 PM
Victor Bazarov wrote:
> Kira Yamato wrote:
>> On 2008-01-23 10:24:30 -0500, anon <anon@no.no> said:
>>
>>> mikhal80@gmail.com wrote:
>>>> Is it possible to write a program which would print out it's own
>>>> source code, using C++?
>>> yes, here is one example for free:
>> deep, philosophically...  lol.
> 
> It probably is.  But my dumb compiler complains that there is no
> 'main' in my program...

You need to tweak it a bit (different compiler options). My linker 
complains:
(.text+0x18): undefined reference to `main'
:(
0
anon3413 (206)
1/24/2008 8:47:22 AM
On Jan 23, 10:41 pm, "Bo Persson" <b...@gmb.dk> wrote:
> Victor Bazarov wrote:
> > Kira Yamato wrote:
> >> On 2008-01-23 10:24:30 -0500, anon <a...@no.no> said:

> >>> mikha...@gmail.com wrote:
> >>>> Is it possible to write a program which would print out it's own
> >>>> source code, using C++?

> >>> yes, here is one example for free:

> >> deep, philosophically...  lol.

> > It probably is.  But my dumb compiler complains that there is no
> > 'main' in my program...

> But other compilers actually once compiled this, ran it, and produced
> an identical empty output.

For what system?  In a hosted environment, a C++ program must
contain a function main somewhere.

--
James Kanze (GABI Software)             email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
0
james.kanze (9769)
1/24/2008 10:34:16 AM
On Jan 23, 11:45 pm, kwikius <a...@servocomm.freeserve.co.uk> wrote:
> On Jan 23, 11:15 am, mikha...@gmail.com wrote:

> > Is it possible to write a program which would print out it's own
> > source code, using C++?

> Heres my effort FWIW. (BTW, if its a homework assigmment then I
> wouldnt recommend handing the following in).

> Also though it compiles in gcc 3.4 I don't know that the fstream
> declaration in the for loop is actually legal. I have a funny idea it
> isnt for some reason...

Why shouldn't it be?

> #include <fstream>
> #include <string>
> #include <cassert>
> #include <iostream>

> template <typename T1, typename T2>
> inline
> void apply(T1* f,T2 & out)
> {
>   std::string str;
>   for(
>    std::ifstream in(f);
>      getline(in,str);
>        out << str <<'\n'
>   ){}
> }

> int main()
> {
>  apply(__FILE__,std::cout);
> }

When I tried it, it worked in the directory where I compiled it,
but when I copied it to ~/bin, and invoked it from there, it
output an earlier suggestion---the one without a main.

--
James Kanze (GABI Software)             email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
0
james.kanze (9769)
1/24/2008 10:38:04 AM
On Jan 24, 10:38=A0am, James Kanze <james.ka...@gmail.com> wrote:
> On Jan 23, 11:45 pm, kwikius <a...@servocomm.freeserve.co.uk> wrote:
>
> > On Jan 23, 11:15 am, mikha...@gmail.com wrote:
> > > Is it possible to write a program which would print out it's own
> > > source code, using C++?
> > Heres my effort FWIW. (BTW, if its a homework assigmment then I
> > wouldnt recommend handing the following in).
> > Also though it compiles in gcc 3.4 I don't know that the fstream
> > declaration in the for loop is actually legal. I have a funny idea it
> > isnt for some reason...
>
> Why shouldn't it be?

I think I had problems once upon a time. It may have been ambiguity
with function declarations, not being in a for statement, which was
the problem before though.

<...>

> When I tried it, it worked in the directory where I compiled it,
> but when I copied it to ~/bin, and invoked it from there, it
> output an earlier suggestion---the one without a main.

Yes! It was hard solving that one as well but I figured it eventually.
Isnt that even more useful than the original application?... its
multipurpose :-)

IIRC the file macro gives the full path with VC++ but not gcc.

regards
Andy Little





0
andy199 (808)
1/24/2008 3:13:47 PM
kwikius <andy@servocomm.freeserve.co.uk> writes:
>> When I tried it, it worked in the directory where I compiled it,
>> but when I copied it to ~/bin, and invoked it from there, it
>> output an earlier suggestion---the one without a main.
>
> Yes! It was hard solving that one as well but I figured it eventually.
> Isnt that even more useful than the original application?... its
> multipurpose :-)

But it's not what's specified.

So how could you write a program that writes a copy of its source,
without relying on run-time external files other than the executable,
since they may not be available?

-- 
__Pascal Bourguignon__
0
pjb (7869)
1/24/2008 4:16:55 PM
On Jan 23, 6:15=A0am, mikha...@gmail.com wrote:
> Is it possible to write a program which would print out it's own
> source code, using C++?

That's old. The trick is to get the compiler
to spit out the entire source code from
messages produced during compilation.
Socks
0
puppet_sock (479)
1/24/2008 4:30:09 PM
* Pascal J. Bourguignon:
> kwikius <andy@servocomm.freeserve.co.uk> writes:
>>> When I tried it, it worked in the directory where I compiled it,
>>> but when I copied it to ~/bin, and invoked it from there, it
>>> output an earlier suggestion---the one without a main.
>> Yes! It was hard solving that one as well but I figured it eventually.
>> Isnt that even more useful than the original application?... its
>> multipurpose :-)
> 
> But it's not what's specified.
> 
> So how could you write a program that writes a copy of its source,
> without relying on run-time external files other than the executable,
> since they may not be available?

quine.

Cheers, & hth.,

- Alf

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
0
alfps (7389)
1/24/2008 4:57:34 PM
"Alf P. Steinbach" <alfps@start.no> writes:

> * Pascal J. Bourguignon:
>> kwikius <andy@servocomm.freeserve.co.uk> writes:
>>>> When I tried it, it worked in the directory where I compiled it,
>>>> but when I copied it to ~/bin, and invoked it from there, it
>>>> output an earlier suggestion---the one without a main.
>>> Yes! It was hard solving that one as well but I figured it eventually.
>>> Isnt that even more useful than the original application?... its
>>> multipurpose :-)
>> But it's not what's specified.
>> So how could you write a program that writes a copy of its source,
>> without relying on run-time external files other than the executable,
>> since they may not be available?
>
> quine.

I know, but the OP still doesn't know.  Let's try to make him try to
write it!

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

HEALTH WARNING: Care should be taken when lifting this product,
since its mass, and thus its weight, is dependent on its velocity
relative to the user.
0
pjb (7869)
1/24/2008 7:02:27 PM
Puppet_Sock <puppet_sock@hotmail.com> writes:

> On Jan 23, 6:15�am, mikha...@gmail.com wrote:
>> Is it possible to write a program which would print out it's own
>> source code, using C++?
>
> That's old. The trick is to get the compiler
> to spit out the entire source code from
> messages produced during compilation.

Then it wouldn't be the program that would print out its own source
code, it would be the compiler.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

HEALTH WARNING: Care should be taken when lifting this product,
since its mass, and thus its weight, is dependent on its velocity
relative to the user.
0
pjb (7869)
1/24/2008 7:03:20 PM
red floyd wrote:
> 
> Allow me to correct Pascal's code:
> 
> int main()
> {
>    // add something here to print its own source.
>    // this is left as an exercise to the reader
>    return 0;
> }

Non-portably and as a first thought I can think of this for my system:


#include <cstdlib>

int main()
{
	std::system("cat main.cc");
}


It outputs:

[john@localhost src]$ ./foobar-cpp
#include <cstdlib>

int main()
{
         std::system("cat main.cc");
}

[john@localhost src]$
0
ivranos1 (46)
1/24/2008 7:14:26 PM
Ioannis Vranos wrote:
> 
> Non-portably and as a first thought I can think of this for my system:
> 
> 
> #include <cstdlib>
> 
> int main()
> {
>     std::system("cat main.cc");
> }
> 
> 
> It outputs:
> 
> [john@localhost src]$ ./foobar-cpp
> #include <cstdlib>
> 
> int main()
> {
>         std::system("cat main.cc");
> }
> 
> [john@localhost src]$


This can be improved my specifying int main(int argc, char **argv), 
taking as an argument the source file. The program requirements doesn't 
specify that arguments are prohibited.

But regarding portability, that isn't portable too.
0
ivranos1 (46)
1/24/2008 7:20:59 PM
mikhal80@gmail.com a �crit :
> Is it possible to write a program which would print out it's own
> source code, using C++?

I am not very confident with this but I think there are debugging 
options or formats that embedded the source code in the executable... If 
a programm is able to display these informations it surely can be 
executed againsts itself.
0
1/24/2008 7:22:39 PM
On Jan 24, 2:03=A0pm, Pascal Bourguignon <p...@informatimago.com> wrote:
> Puppet_Sock <puppet_s...@hotmail.com> writes:
> > On Jan 23, 6:15=A0am, mikha...@gmail.com wrote:
> >> Is it possible to write a program which would print out it's own
> >> source code, using C++?
>
> > That's old. The trick is to get the compiler
> > to spit out the entire source code from
> > messages produced during compilation.
>
> Then it wouldn't be the program that would print out its own source
> code, it would be the compiler.

You know, I never get the memos. When did the memo
go around that we were all supposed to be idiots?

Me: The trick is to get the compiler to do it.
You: Then it would be the compiler doing it.
Me: (Does my Benny Hill imitation, slapping you
     repeatedly on the back of the head like
     B.H. did that little bald guy.)
Socks
0
puppet_sock (479)
1/24/2008 7:42:59 PM
I cannot see why it would be impossible to write a decompiler that was 
carefully coded to decompile itself to its own source.
Is there some computation theory that I am missing?

> Is it possible to write a program which would print out it's own
> source code, using C++? 


0
1/24/2008 7:46:44 PM
>I cannot see why it would be impossible to write a decompiler that 
>was carefully coded to decompile itself to its own source.
> Is there some computation theory that I am missing?
>
>> Is it possible to write a program which would print out it's own
>> source code, using C++?

Appologies if this has already been answered... yes it is possible, 
and such a program is called a quine. 
http://en.wikipedia.org/wiki/Quine_%28computing%29

One of the examples from that page is a C program, which should also 
be a valid C++ program.

As to the question about the decompiler... I don't see why it would be 
impossible in theory. Of course, the higher-level the decompiled code 
you want (e.g. functions, classes etc..) the more complicated your 
compiler would be. And so you'd be more likely to write code using 
more classes and language features which would make your job harder.

Mark


0
kenshin_40 (20)
1/24/2008 8:18:09 PM
On Jan 24, 4:16=A0pm, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
> kwikius <a...@servocomm.freeserve.co.uk> writes:
> >> When I tried it, it worked in the directory where I compiled it,
> >> but when I copied it to ~/bin, and invoked it from there, it
> >> output an earlier suggestion---the one without a main.
>
> > Yes! It was hard solving that one as well but I figured it eventually.
> > Isnt that even more useful than the original application?... its
> > multipurpose :-)
>
> But it's not what's specified.

=46rom the O.P....

"Is it possible to write a program which would print out it's own
source code, using C++? "


As explained above  I've even thrown in some very useful extra
functionality!!  :-)

regards
Andy Little


0
andy199 (808)
1/25/2008 12:01:10 AM
On Thu, 24 Jan 2008 20:03:20 +0100, Pascal Bourguignon wrote:

> Puppet_Sock <puppet_sock@hotmail.com> writes:
> 
>> On Jan 23, 6:15 am, mikha...@gmail.com wrote:
>>> Is it possible to write a program which would print out it's own
>>> source code, using C++?
>>
>> That's old. The trick is to get the compiler to spit out the entire
>> source code from messages produced during compilation.
> 
> Then it wouldn't be the program that would print out its own source
> code, it would be the compiler.

Right. So if you ran a compiled executable of a program that "prints out 
its own source code" then I guess it wouldn't be the program that prints 
out its own source code, it would be the run-time system.

-- 
Lionel B
0
me4 (19624)
1/25/2008 10:56:48 AM
I looked at some of those examples of a quine the other day.  It looked like 
there was a constraint where you could not have any input files. So, a 
decompliler that took itself as input would not be legal.
The other thing I noticed is they seem to cheat by using printf.  Why is it 
legal to use external sources in libraries and not also print the source for 
those libraries?



"Mark Holland" <kenshin_40@htomail.com> wrote in message 
news:xLqdnWmTQ7IbbwXanZ2dnUVZ8uOdnZ2d@pipex.net...
> >I cannot see why it would be impossible to write a decompiler that was 
> >carefully coded to decompile itself to its own source.
>> Is there some computation theory that I am missing?
>>
>>> Is it possible to write a program which would print out it's own
>>> source code, using C++?
>
> Appologies if this has already been answered... yes it is possible, and 
> such a program is called a quine. 
> http://en.wikipedia.org/wiki/Quine_%28computing%29
>
> One of the examples from that page is a C program, which should also be a 
> valid C++ program.
>
> As to the question about the decompiler... I don't see why it would be 
> impossible in theory. Of course, the higher-level the decompiled code you 
> want (e.g. functions, classes etc..) the more complicated your compiler 
> would be. And so you'd be more likely to write code using more classes and 
> language features which would make your job harder.
>
> Mark
>
> 


0
1/25/2008 2:02:57 PM
Matt wrote:
 >
> I looked at some of those examples of a quine the other day.  It looked like 
> there was a constraint where you could not have any input files. So, a 
> decompliler that took itself as input would not be legal.
> The other thing I noticed is they seem to cheat by using printf.  Why is it 
> legal to use external sources in libraries and not also print the source for 
> those libraries?


Interesting question. However any standard library headers #included, in 
reality they can be like a switch, with no actual header file existing.
0
ivranos1 (46)
1/25/2008 2:56:10 PM
Ioannis Vranos <ivranos@no.spamfreemail.nospam.gr> writes:

> Matt wrote:
>>
>> I looked at some of those examples of a quine the other day.  It
>> looked like there was a constraint where you could not have any
>> input files. So, a decompliler that took itself as input would not
>> be legal.
>> The other thing I noticed is they seem to cheat by using printf.
>> Why is it legal to use external sources in libraries and not also
>> print the source for those libraries?
>
>
> Interesting question. However any standard library headers #included,
> in reality they can be like a switch, with no actual header file
> existing.

Normally, I don't consider using libraries such as stdio or iostream
as cheating, since they're part of programming in C or C++.  But I
don't mind using C or C++ compilers for what they are, some passable
portable assemblers, and writting raw assembly code we don't need any
header, since we always have access to the instructions of the POSIX
virtual machine, namely write(2) which is all we need to "print" some
text.


Here is a simplistic solution.  When you edit it, you replace the
contents of quine[] by the new sources, escaping " and \ and putting
each line in a string.  Then you update the literal 19 correponding to
the number of the first line of the initializer of quine[].

----------------------------quine.c++----------------------------------
// No header, no library.
// But we'll use the OS to "print" our sources.
extern "C"{ int write(int fd,const char* buffer,int size); }
int len(const char* str){
    int l=0; while((*str)!=0){++str;++l;} 
    return(l);}
void escape(char* dst,const char* src){
    int i=0;
    for(int j=0;src[j]!=0;++j){
        switch(src[j]){
        case '"': case '\\': dst[i++]='\\'; // fallthru
        default: dst[i++]=src[j]; }}
    dst[i]=0;}
int main(void){
    char  left   []="        \"";
    char  right  []="\",*";
    char  newline[]="*";
    char  buffer[128];
    char* quine  []={
        "// No header, no library.",
        "// But we'll use the OS to \"print\" our sources.",
        "extern \"C\"{ int write(int fd,const char* buffer,int size); }",
        "int len(const char* str){",
        "    int l=0; while((*str)!=0){++str;++l;} ",
        "    return(l);}",
        "void escape(char* dst,const char* src){",
        "    int i=0;",
        "    for(int j=0;src[j]!=0;++j){",
        "        switch(src[j]){",
        "        case '\"': case '\\\\': dst[i++]='\\\\'; // fallthru",
        "        default: dst[i++]=src[j]; }}",
        "    dst[i]=0;}",
        "int main(void){",
        "    char  left   []=\"        \\\"\";",
        "    char  right  []=\"\\\",*\";",
        "    char  newline[]=\"*\";",
        "    char  buffer[128];",
        "    char* quine  []={",
        "    };",
        "    right[2]=10;",
        "    newline[0]=10;",
        "    for(int i=0;i<sizeof(quine)/sizeof(quine[0]);++i){",
        "        if(i==19){",
        "            for(int j=0;j<sizeof(quine)/sizeof(quine[0]);++j){",
        "                write(1,&left[0],len(left));",
        "                escape(buffer,quine[j]);",
        "                write(1,buffer,len(buffer));",
        "                write(1,&right[0],len(right));",
        "            }",
        "        }",
        "        write(1,quine[i],len(quine[i]));",
        "        write(1,&newline[0],len(newline));",
        "    }",
        "    return(0);",
        "}",
    };
    right[2]=10;
    newline[0]=10;
    for(int i=0;i<sizeof(quine)/sizeof(quine[0]);++i){
        if(i==19){
            for(int j=0;j<sizeof(quine)/sizeof(quine[0]);++j){
                write(1,&left[0],len(left));
                escape(buffer,quine[j]);
                write(1,buffer,len(buffer));
                write(1,&right[0],len(right));
            }
        }
        write(1,quine[i],len(quine[i]));
        write(1,&newline[0],len(newline));
    }
    return(0);
}
----------------------------quine.c++----------------------------------

g++ quine.c++ -o quine && ./quine > quine.out && diff quine.c++ quine.out


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"What is this talk of "release"?  Klingons do not make software
"releases".  Our software "escapes" leaving a bloody trail of
designers and quality assurance people in its wake."
0
pjb (7869)
1/25/2008 11:20:20 PM
Reply:

Similar Artilces:

How to link obj's from c-source with obj's from c++-source
Hi, I compiled 2 simple source-files with cl -c main.cpp and cl -c test.c. test.c contains just a simple function, which is declared in test.h. test.h is included in test.c and in main.cpp. When I try to link the objects with link main.cpp test.c -out:prog.exe I get the error: "main.obj : error LNK2019: unresolved external Symbol "int __cdecl greater(int,int)" (?greater@@YAHHH@Z), called in function _main prog.exe : fatal error LNK1120: 1 unresolved external Symbol" What have I to do, to be able to link those objects together? Guido Belligoi "Guido Belligoi" ...

S*S'-> make a code program of DIFF (S) for S to excute expression:S*S, ( S=vector, S'=dS/dt). ideas to all?
hello everyone, now i need a help of ideas for a program style from all to find :S*S'. here we would not be able to use directly Diff( S) cuz of error of unsame size of S & diff( S). soo i dlove to get any code PROGRAM STYLEs for function S' ( dS/dt) to Find S*S', with S: vector, for example as a begining input: t=0:10; S=2*t.^3 +3*t; Now make a code program to DEFINE S' by ALGORITHM of MATH. dear all, my question going well for understanding?? iam waiting for all. ( hey, give a trial into the world of Math of Algorithm for function & diveritative)-) ...

print a vs print '%s' % a vs print '%f' a
Hi, While working on some python C extensions, I got curious in how things work for printing float objects (and C-level objects which inherit from it). In python 2.6, I understand that the formatting went into surgery for more consistency across platforms. So for example, on windows, complex('inf') would be printed 'inf', and not '1.#INF'. However, I would like some clarifications if possible about the following: a = complex('inf') print a # -> print 'inf' print '%s' % a # -> print 'inf' print '%f' % a # -> print '1...

two questions: and's inside if's and checking the return code of a program
Hello all: I have two questions concerning sh shell programming: 1. is there a way to test a conditional containing and's and or's (such as if ( cond1 && cond2 ) ) other than using two if statements? 2. is there a way to check the return code of a c program (i.e.I have a c program that returns ints based on whether or not it fails. I want to take action based on these codes) Thanks, Jeremy In article <1135704919.620355.22430@z14g2000cwz.googlegroups.com>, tucker.jeremy@gmail.com wrote: > Hello all: > > I have two questions concerning sh shell programming: ...

Re: SAS Codes for calculating Moran's I and Geary's C
imamx8@gmail.com wrote: > Does anybody have written a SAS code for calculating Moran's I and >Geary's >C? Could you share that with us or me? This is on the internet, and I found it just by searching using Google. http://www.stat.lsu.edu/faculty/moser/spatial/autocorr-body.html It uses SAS/IML. You could compute both of these without SAS/IML, since they're merely scaled cross-products. In fact, you could read a weight matrix into a 2-D array in a DATA step and do it all in one DATA step instead. But I'm not sure that you ought to. I'm not a big fan of bli...

Source Code for Feuer's MFC Programming
I have just picked up a copy of Alan Feuer's MFC Programming from a library in town. The book is in good condition, and looks like quite a decent MFC tutorial. Unfortunately, the accompanying CD seems to have gone walkabout. If anybody knows a place where I could legally get the source code, kindly point me in the right direction. Thanks in advance Isaac ...

Trial of Musatov's theory: double spaced 'e x p a n d s' and single spaced 'c o n t r a c t s'. Does the spacing post-processing appear equal? If so, what force was lost and where did it g
Musatov's theory 'The space between spaces expands and contracts.' Would this give time a direction? Musatov ...

Re: SAS Codes for calculating Moran's I and Geary's C #2
Dear All: Is there anybody who has implemented the spatial lag model: "y =3D pWy + X= B + error" and the spatial error model: "y=3DXB + Lamda*W*E + e" in SAS using maximum likelihood method? These models are proposed by Luc Anselin and implemented in his GeoDa package. Daniel Griffith has some SAS code for spatial autocorrelation model using proc nlin. His core code goes like this= : /*GRIFFITH SAS CODE FOR SPATIAL AUTOCOR. MODEL*/ data step1; start=3D0.999; finish=3D1; inc =3D 0.095; run; data step2; if _n_=3D1 then set step1; infile eigen; input obs eigenw; array j...

It's on-it's off-it's on, it's off -WHY?
IS THIS THE CORRECT FORUM? Hope so. We have three computer networked at home...all with Windows XP. one of those is a laptop. Some mornings all 3 can see each other and transfer files...then mysteriously one or more will disappear. No contact....then later it's back. The laptop is the worst. Most often it won't let us in...but sometimes it will. No obvious reason. The most INFURIATING part is the message "see your administrator". Dammit Bill Gates...don't you realize that most networks are small offices without a Majestic Royal Administrator sitting his i...

how to write C program that copy's it's self onto the hard drive, while its running?
I am a beginner C programmer, this is actually my first programming lanugage, besides html, cgi, and javascript. I am looking for a way to make an .exe file, or a copy of my own file. I have tried writing a file, compling it, and reading it in a notepad, then writing a program to write it again, but i have had no luck. I assure you i'm not trying to create the next big virus, or worm, but only trying to expaned my knowledge on what programming language i will take. C is my perferred taste, though i may go into java if this dosen't work out. aspiring programmer Jon 15 jon wrote: >...

HELP on "C" DLL internal code for LAN's and WAN's use
To all wizards: I have a "C" DLL file already built and running, but I want to have the DLL accessible(callable) from anyway within a LAN and/or WAN( and even multi-WAN's), or even on a PC. I built the DLL file, via VC++'s (v6.0) ATL COM AppWizard area, and it works quite well. But as for using the DLL file on LAN's and Wan's, do I need to add any more code into the DLL file, so it will work on/under a network and be callable anywhere on a LAN's or WAN's or even on standalones by any and all application(s). If I need some additional code, can you ...

More factory sealed FPGA's with C of C's
I have more FPGA's with C of C's that I can supply below facotry direct pricing. Small quantities ok. These have all been purchased thru factrory direct channels and in most cases I can tell you exactly where they came from. We have aquired these from VMI and SMI programs that we have with major OEM's and CM's. Jon E. Hansen Pyramid Technologies Inc. jon@pyramidemail.com www.pyramidtechnologiesinc.com (949)864-7745 Direct (949)636-1416 Cell CERTIFIED ISO 9001:2000 XC5VFX70T-1FF1136C XC5VFX70T-1FFG1136C XC5VLX50-1FF676C XC5VLX330-1FF1760C XC4VLX100-10FFG1148C XC2V3000-4FG...

Source Code to Plauger's "Standard C Library"
Does anyone know where I can download the source code to accompany PJ Plauger's book "The Standard C Library"? I find a lot of references for the library, but not the actual source code from the book. Any help would be appreciated! The Grue -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 The Grue - James T. Sprinkle wrote: > Does anyone know where I can download the source code to accompany PJ > Plauger's book "The Standard C Library"? I find a lot of references for the > library, but not the actual source code from the book. Any help would be > a...

what's wrong with this code? it's ADI ts201s code
hi, there, the following code is the do DMA transfer and check if the dma transfer was finished or not. when I am in step by step debug mode, the code runs well. But if I run the whole code, the program will never stop, it always in the endless loop. Would anybody give me any clue for this prolem? thanks. xr0 =Source ;; xr1=0x00100040;; xr2=0x00;; xr3=0x47000000;; DCS0 =xr3:0;; yr0 = Destination;; yr1=0x00100040;; yr2=0x00;; yr3=0x47000000;; DCD0 = yr3:0;; DMA0_Finished: xr9:8=DSTAT;; xr10=0x03;; xr8=FEXT R8 by R10;; xr9=0x02;; xr8=r8-r9;;...

Is there in the C++'s standard a note on how large the size of an array is allowed so that the code containing the array's definition is portable?
Hello. First, I would like to give a short description on how the information in this message is structured. I will state my question, then I will give all the text I know in the C++ specification, to relate with my question. In the end I give my thoughts on this subject. [[The question]] How many items can there be defined in a C++ array so that the code containing the C++ array makes a well-defined C++ program considering that the rest of the C++ program is well-formed? [[Text from the C++ specification]] 8.3.4 Arrays [dcl.array] In a declaration T D where D has the f...

anyone has Jeff Prosise's programming mfc 2nd edition CD / source codes?
I bought used book and it is missing the Cd. Anyone has it or any place to download it? thanks a bunch!! ...

M code into programming C code or MATLAB programming code
hallo firends, Can any body help me write this below code into MATLAB object oriented or C code form please? M=50; % total number of periods. (choose for 1s duration) f0 = 50; % fundamental AC frequency T0 = 1/f0; %fundamental AC period T = M*T0; %Time for M periods (integer M) N=30; % sample points per period. dt = T0/N; % Sample at N points per period (integer N > 20) t = dt*[1:M*N-1]; % Sampling time array A0=120/2; % amplitude of AC signal. Divide by 2 or maybe sqrt (2) ? AC=A0*sin(f0*t*2*pi); % create AC signal. DC0=50; % DC amplitude DC=DC0*ones(1,length...

What's the C++ community's feeling about lambda(or closure) in C++?
I know this topic sounds kind of old and dry(and shallow, maybe :)), but, you see, lately I found that there's all the fuss about closure in Java, so I poked around for a little, and did find some valuable information. And I started to remember that there were a proposal(actually two) about lambda/closure for C++(see http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2006/n1968.pdf and http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2006/n1958.pdf) They're all pretty well-formed and sound, though I found Bjarne's a little more comprehensive. It simply seems that the closure id...

Deitel & Deitel's How to Program C++ 6th Edition chapters 1-22 full code solutions for $50
If you need help with your learning from Deitel & Deitel's How to Program C++ 6th Edition and need these solutions send us an email at instructors.team[at]gmail.com. Code solutions for $50. All code solutions for ch 1-22. instructors.team@gmail.com wrote: > If you need help with your learning from Deitel & Deitel's How to > Program C++ 6th Edition and need these solutions send us an email at > instructors.team[at]gmail.com. > Code solutions for $50. All code solutions for ch 1-22. -- Note that robinton.demon.co.uk addresses are no longer valid. 1) W...

Deitel & Deitel's How to Program C++ 6th Edition chapters 1-22 full code solutions for $50
If you need help with your learning from Deitel & Deitel's How to Program C++ 6th Edition and need these solutions send us an email at instructors.team[at]gmail.com. Code solutions for $50. All code solutions for ch 1-22. ...

Deitel & Deitel's How to Program C++ 6th Edition chapters 1-22 full code solutions for $50
If you need help with your learning from Deitel & Deitel's How to Program C++ 6th Edition and need these solutions send us an email at instructors.team[at]gmail.com. Code solutions for $50. All code solutions for ch 1-22. On May 1, 6:32=A0am, instructors.t...@gmail.com wrote: > If you need help with your learning from Deitel & Deitel's How to > Program C++ 6th Edition and need these solutions send us an email at > instructors.team[at]gmail.com. > Code solutions for $50. All code solutions for ch 1-22. Probably worthless, since the OP doesn't seem to know the d...

Deitel & Deitel's How to Program C++ 6th Edition chapters 1-22 full code solutions for $50
If you need help with your learning from Deitel & Deitel's How to Program C++ 6th Edition and need these solutions send us an email at instructors.team[at]gmail.com. Code solutions for $50. All code solutions for ch 1-22. ...

For Doris the bat's alleged, within me it's great, whereas without you it's printing main.
She'd twist hitherto than recommend with Fahd's parliamentary cage. Try filing the ward's striped section and Perry will hate you! He will formerly move brave and means our tight, scary moves on top of a south. Occasionally, it stages a succession too asleep into her extensive beach. Tell Paulie it's labour limiting no longer a discretion. Brahimi! You'll merge booklets. Yesterday, I'll hold the sum. Try not to chew the scripts absolutely, rate them privately. One more conceptual competent guns nearby weigh as the recent maids rub. Tomorrow, Ben ne...

[News] [Rival] Microsoft's 'Open Source' Labs Spread C**p on Linux, Free Software
Microsoft director out to 'debunk mythology around open source' ,----[ Quote ] | "The Free Software movement is dead. Linux doesn't exist in 2007. Even | Linus has got a job today." Controversial statements from the head | of Microsoft's Linux Labs, Bill Hilf. | | [...] | | Hilf accused his former employers, IBM, of starting a standards war | simply because they wanted a part of the Office market. People do | not want ODF (Open Document Format), but they want a way to control | the information they create, he claimed. `---- http://www.bangkokpost.com/090507_Databa...

TCP/UDP 'C' source code resources
Can anyone point me in the direction of any code resources, in either 'C' or C++? I need some example packet analysis code, to assist me with a project I am working on for my dissertation. Some more information can be found at http://80.4.4.163/dissertation/Home.htm for those who are interested. Many thanks, DN "David Norris" <david.norris23@ntlworld.com> wrote in message news:HJSLa.8658$sh4.736013@newsfep2-win.server.ntli.net... > Can anyone point me in the direction of any code resources, in either 'C' or > C++? I need some example packet...

Web resources about - A program which would print out it's own source code - possible or not? - comp.lang.c++

Resources last updated: 2/16/2016 10:55:01 AM