C programming question ....
Roger Oberholtzer
roger
Wed Nov 8 11:23:49 PST 2006
On Wed, 2006-11-08 at 10:16 -0600, Ben Duncan wrote:
> Ok, wrote this lil' ole snippet of code to test a theory ...
> -------------------------------------------------------------------
>
> typedef void* my_pointer ;
>
> struct rlib;
> typedef struct rlib rlib;
> typedef void* my_pointer ;
>
> struct rlib;
> typedef struct rlib rlib;
>
> struct rlib_signal_functions {
> int (*signal_function)(rlib *, my_pointer);
> my_pointer data;
> };
>
> struct rlib_metadata {
> int rlib_value ;
> int rval_formula ;
> char rlib_from_xml [80] ;
> char xml_formula [80] ;
> char rlib_pcode [120] ;
> char *formula_code ;
> };
>
> struct rlib {
> int current_page_number;
> int current_line_number;
> int detail_line_count;
> int start_of_new_report;
>
> int font_point;
>
> int current_font_point;
>
> char *output_encoder_name;
>
> };
>
> int main ( int Argc, char **Argv )
>
> struct rlib_signal_functions {
> int (*signal_function)(rlib *, my_pointer);
> my_pointer data;
> };
>
> struct rlib_metadata {
> int rlib_value ;
> int rval_formula ;
> char rlib_from_xml [80] ;
> char xml_formula [80] ;
> char rlib_pcode [120] ;
> char *formula_code ;
> };
>
> struct rlib {
> int current_page_number;
> int current_line_number;
> int detail_line_count;
> int start_of_new_report;
>
> int font_point;
>
> int current_font_point;
>
> char *output_encoder_name;
>
> };
>
> int main ( int Argc, char **Argv )
>
> ......
> ...................
> -------------------------------------------------------
>
> And it COMPILES and works. SO, it seems that
>
> struct rlib;
> typedef struct rlib rlib;
>
> Is a way to prototype a Structure ...
>
> Ok, my questions to the REAL C guru's out there is:
> Why would you want to do such a thing when simply moving
> the ACTUAL structure ahead of things would solve having to
> create extra lines of code protyping the structure ?
1. Bad habits.
2. Never worked on a project where one had to share code.
3. Likes to make code unclear so can seem so clever when explaining what
it really does.
4. Likes to feel stupid when code can't compile on a different platform.
When you first posted this I was tempted to reply something nasty. But
then I had a cup of coffee and calmed down. In addition to having C
programming as my primary task (for over 20 years), I manage a number of
programmers. Rule one: don't be a smart ass. You are only really clever
if you can make it obvious what the code does by good design. Code such
as you posted would probably be rejected by any decent open source
project. If not immediately, then eventually. If not eventually, then it
would be because the project died due to such sloppiness.
And this is my calm response.
--
Roger Oberholtzer
More information about the Linux-users
mailing list