[Courses] [C] Lesson Three: Basic Declarations & Expressions

Eugene Teo eugene.teo at eugeneteo.net
Fri Oct 11 23:00:19 EST 2002


<quote who="Lorne Gutz">
u> IMO the  'int   main( void )' is preferable and by the way
u> main can have as many as 3 parameters.

In short, personal preference. It is important to adopt a personal
style in developing applications.

u> Its just to easy to become sloppy and cryptic in C.  The 
u> little program you have written below is a good example.
u> In 6 months or a year would you be able to read it??

Nope :-) Actually it is meant to be that way. Cryptic one-liners.
Just for the fun of it!

u> Eugene, you asked about the fork() function.  You can keep track
u> of the childern a process has sponed off with the PIDs.  A child
u> can always determind is parents PID with the function
u> getppid().

Yup, that is what I found out but right now, I am learning to trace
it without writing and running the program. I am expecting my professor
to come up with such weird questions in the coming exam. something like
fork(); fork(); fork(); for(i = 0; i < 3; ++i) if(!fork()) break; 
then he will, how many forks are there, how many children,
grandchildren, etc :-) I am trying to guess what kind of weird questions
he will ask. 

u> Now pipes......I like to avoid them becasue they are not compatable
u> from one platform to another.  Shared memory works better for me,
u> if and when the communication is between pocesses that are on 
u> the  same computer.  I find it more stable, faster, and much easier 
u> to understand what is going on when debugging is required.  Its 
u> also simple to use the signal() to send flags from on process to 
u> another.

To be frank, I have yet to write this part, and I am hoping to read it
up tomorrow, and try it. So much things to learn, so little time. 

u> Your in my world with this stuff, so don't be shy with questions.

Thanks Lorne. I really appreciate your kind offer to help. I will ask
questions.

Eugene

u> 
u> cheers
u> Lorne
u> 
u> 
u> 
u> > also, for the main(), it takes no parameter and returns an integer by
u> > default, so there is no need to explicitly do "int main(void)". just
u> > main() will do.
u> >
u> > One advice I can give is to learn to write routines like test integers,
u> > doing [A-Z] to [a-z] conversions, etc. man ascii and you will be
u> > enlightened.
u> >
u> > Ok just for the fun of it, you might want to try to compile
u> > my one-liner:
u> >
u> > main(i){putchar(182623909>>(i-1)*5&31|!!(i<7)<<6)&&main(++i);}
u> >
u> > :-)
u> >
u> > Anyone has any notes to share on the following topics?
u> > Graph diagrams on multiple fork calls, with pipe and dup2?
u> > I am learning these now, and kind of confused when it deals
u> > with more than 3-4 fork()s, especially when it comes to
u> > identifying who are children, grandchildren, etc.
u> >
u> > Eugene
u> 
u> -- 
u> Lorne Gutz
u> Baseband Design Group
u> Supervisor H/W Support
u> 
u> 

-- 
eMail: eugeneteo at eugeneteo.net, eugeneteo at null.cc.uic.edu
gpg pub_key: http://null.cc.uic.edu/~eugeneteo/eugeneteo.asc
main(i){putchar(182623909>>(i-1)*5&31|!!(i<7)<<6)&&main(++i);}




More information about the Courses mailing list