You may have heard of the International Obfuscated C Code Contest ... there is a 1990 entry you can probably relate to.

This code primarily solves differential equations. But if you give it special parameter, -r, it reverses lines in a file. Then if you run the -r on the original source code and recompile it, it becomes a sort program. And if you sort the orignal source code and compile, it becomes a Fibonacci sequence generator. And a -r parameter on the sort program, applied to itself, gives you back the original code.

http://www.au.ioccc.org/1990/theorem.hint
http://www.au.ioccc.org/1990/theorem.c

Terry


Phil Middlemiss wrote:
Thanks Terry,
 
actually it turned out that it was a multiplication right next to a regular pointer indirection (ie x * *p(blahblah)).
<rant>
The code was writen in 1990 and released by the US National Geophysical Data Center and it's as ugly as sin. I don't know whether it is typical of procedural code written in C from that period (or from govt centers), but I suspect it breaks whatever rules for structure and design that they had even then! For example, apart from things like gotos and incredibly short meaningless variable names, it has routines that do two completely different tasks depending on a flag that you pass into it (ie two routines in one - just pass a flag to get it to do something else), and stuff like the following:
 
for (m=0,D3=1,D4=(n+m+D3)/D3; D4>0; D4--,m+=D3)
etc
 
where the m is not used in the loop and should have just been initialised outside it! There's more, but you get the idea.
</rant>
It also doesn't help that I'm translating code that carries out calculations that are well above my comprehension (calculates the 2000 Epoch World Magnetic Model for a given Lat, Long, Altitude, and Year using spherical-harmonic Gauss coefficients - whatever they are).
Cheers,
Phil.
----- Original Message -----
From: Terry
Sent: Monday, April 19, 2004 3:42 PM
Subject: Re: [DUG] Converting some code from C

** is double indirection. Pointer to a pointer.

If you have ...
char * p;
then *p is a char, p is a pointer to a character.

If you have...
 char ** p;
 then **p is a character, *p is a pointer to a character, p is a pointer to a pointer to a character.

All parameters in C are passed by value. So if you want to pass in a var parameter, you need to pass in a pointer to the value to be referenced/modified. But if you want to be able to change where the pointer is pointing from within a function, you need ** (otherwise you just change what the pointer is pointing to).

Terry

Phil Middlemiss wrote:
Thankyou.
 
What does the ** operator in C?
 
Cheers,
Phil.

_______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi



_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi

Reply via email to