/*
To a C/C++ compiler this file looks like legal C and it will build this file into an executable.
To a webrowser this same file is completely browsable. So you can see that it is possible to provide hyperlinked documentation to C/C++ source code in the same file!
This reduces the amount of documentation time normally needed when a code change is made. Normally the code is changed, the comments in the source file is updated, but the "official" documentation to the code module is left to be updated "later". A lot of times that involes cutting and pasting comments in the source file into the document file and all the reformatting that needs to be done.
Well NO MORE! By just a few simple HTML tags and smart placement of C /* */ comment blocks, the official documentation for the source code is the source code itself. This is of course a simplistic example and much fancer code displays could be done, using frames and such.
This file is compatible with IE 5.0 and Netscape 4.61. And, of course, it is C source!
Give it a TRY! Save this page and then feed it to your favorite compiler! (You may have to strip off anything before the first comment line above due to my homepage hosting site putting a banner there.)
void hello() void world()
Source: */ #include // // normally we would put these in our header file. void hello(); void world(); int main(int, char** ) { // here is some code and some comments and such. hello(); world(); return(0); // to make the compiler happy } /*
INPUTS: It takes no inputs.
OUTPUTS: It outputs the string "hello" to stadard out.
Called by:
main()
*/ // // Function: hello() // // puts out hello to standard output and it takes no input and returns nothing. void hello() { puts("\nhello "); } /* void world() The only function of the world() function is output "world" each time it is called.
OUTPUTS: It outputs the string "world" to standard out.
*/ // // Function: world() // // // puts out world void world() { puts("world\n"); } /*
We can make use of the <textarea> tag of HTML to encapsulate the C/C++ code and we can use a C comment block to encapsulate the HTML. This puts the C/C++ code segments of the file into scrollable windows that you see above. The basic format for this HTML in C code example is as follows:
/* Start a C comment. It is before the html tag so it gets ignored by the browser. Then you can transition to C or C++ code using a textarea tag like this: */ // Now you can begin C or C++ code // int G_some_variable; void some_function() { G_some_variable = 69; } /* Start a C comment and Then back to HTML by ending the text area: More HTML can go here to conclude your file. */ That last "*/" ends the C comment block that encapsulates the end of the HTML and ends the file. Since it is after the /html tag it is ignored by the web browser (although it may be shown as plain text). Another posibility is to use frames, and have the meat of documentation in a separate HTML file with pointers into a C/C++ soure file that has encapsulated HTML anchor points. I hope to have an example of that soon... Still Another posibility is to use the <XMP> html tag to encapsulate the C/C++ code. This does not have the nice scrollable windows nor the hyperlinking, but instead just presents the code inline as shown below. This would be quick and dirty for those small simple little help functions that seem to pop up and of course for small header files too. For example: <XMP> */ // Here is more C that will compile. // static int another_var; void another_func() { another_var = 11; } /* </XMP> Copyright © 1998, 1999 Mark J. Giebler. This is the end of the HTML/C SOURCE example file. */
That last "*/" ends the C comment block that encapsulates the end of the HTML and ends the file. Since it is after the /html tag it is ignored by the web browser (although it may be shown as plain text).
Another posibility is to use frames, and have the meat of documentation in a separate HTML file with pointers into a C/C++ soure file that has encapsulated HTML anchor points. I hope to have an example of that soon...
Still Another posibility is to use the <XMP> html tag to encapsulate the C/C++ code. This does not have the nice scrollable windows nor the hyperlinking, but instead just presents the code inline as shown below. This would be quick and dirty for those small simple little help functions that seem to pop up and of course for small header files too.
For example:
<XMP> */ // Here is more C that will compile. // static int another_var; void another_func() { another_var = 11; } /* </XMP>
Copyright © 1998, 1999 Mark J. Giebler.
This is the end of the HTML/C SOURCE example file.