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

Lorne Gutz lgutz at vistar.ca
Fri Oct 11 10:20:32 EST 2002


IMO the  'int   main( void )' is preferable and by the way
main can have as many as 3 parameters.

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

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

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

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

cheers
Lorne



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

-- 
Lorne Gutz
Baseband Design Group
Supervisor H/W Support





More information about the Courses mailing list