Thursday, May 9, 2013

C, Writing Large Programs

  This post is summary of Chapter 15 Writing Large Programs from "C Programming, A mordern approach" by K. N. King

15.2 Header Files
    1. What is Header file?
 ->  In computer programming, a header file is a file that allows programmers to separate certain elements of a program's source code into reusable files. Header files commonly contain forward declarations of classes, subroutines, variables, and other identifiers.  <http://en.wikipedia.org/wiki/Header_file
    2.  How do we call header files into other source files?
-> use #include 
-> header files have .h extension
    3. Two primary forms of the #include directive
-> #include <filename>    :   this is used for header files that belongs C's own library. Search the directory in which system header files reside
-> #include "filename"     :   this is used for all other header files including any that we write. Search the current directory, then search the directory in which system header files reside
    4. Sharing Macro Definitions and Type Definitions

example of sharing macro definitions and type definitions
          In this way, we can avoid repeating the same macro and type definitions.


    5. Sharing Function Prototypes
 -> Assume there is a source file containing many functions.  We want to call the functions into the other source file.  To avoid any possble errors, we need function prototypes.  The below illustrates how it is done.
-> To share a function, we put its definition in one source file, then put declarations in other files that need to call the function.  
Example of sharing Function Prototypes


    6. Sharing Variable Declarations
-> int i;                    /* declares i and defines it as well*/
-> extern int i;         /* declares i without defining it */
-> extern informs the compiler that i is defined elsewhere in the program.



    7.  Nested Includes
-> Assume that we have two functions that returns only 0 and 1, in other words, true and false.
-> I will use the previous example.  At the 5. Sharing Function prototypes, we had is_empty and is_full function.  Those two only returns 0 and 1.  So change declaring those at stack.h as
int is_empty(void)  => Bool is_empty(void) 
int is_full(void)      => Bool is_full(void)
  
-> to do this, we need to include the boolean.h file in the stack.h, so it becomes

    8. Protecting Header Files
-> If a source file includes the same header file twice, compilation errors may result. This problem is common when header files include other header files.  Consider the following diagram.
-> As you can see, when prog.c is compiled, file3.h will be compiled twice.
-> To prevent this happening, we protect a header file by enclosing the contents of the file in an #ifndef and #endif pair. Below is the example of protection of boolean.h file.
-> so when the boolean.h file is called twice, preprocessor checks if BOOLEAN_H is defined. And it defines BOOLEAN_H only if it hasn't been defined.


Tuesday, May 7, 2013

How I ended up with my programming job


  I'm 29 years old Korean male living in Tokyo, Japan.



  I've finished my high school education in South Korea, then served military for almost 3 years. After I got out of military, I moved to the U.S., and got bachelors degree in applied math. Since I served military for almost 3 years, and spent 5 years in the university, I was already 28 when I graduated the University.  And more importantly I had no programming knowledge and experience except 1 semester of R language (R is programming language used in statistics world).

  At that time, I was getting tired of being in the U.S. and wanted to see other countries.  And working in Japan seems very attractive to me. So I applied to the company I'm working at now, and got a job.

  About my work place, Asahi Glass Co., in short, AGC, is a company making glasses as you can see from its name. It's pretty big company. It has lots of factories all around the world. And since the company is making glasses, I was expecting doing some kind of factory line management or something similar because I didn't have any practical skills other than some basic math knowledge like set theory or probability.  Really, what can you do with the pure theoretical knowledge? However, not like my expectation, the company gave me a programming job. Um, maybe it was my fault that I didn't mention I had no programming experience?

  One funny thing about getting a job in Japan as a fresh graduate is you will never know what kind of work you are going to do in the company.  At least I and other people who got hired at the same time had no clue what we were going to do in this company.  When the company finally told me that I would be a programmer developing a heat transfer simulation software using Java, I asked them back,
  "Um.. excuse me, but what's heat transfer simulation and what is Java?"

  So basically, to develop the physics simulation software, I had to know heat transfer, fluid dynamics, and Java. And as I mentioned, I'm math major without any programming knowledge.  Also, I didn't really enjoy physics, so I didn't take any physics class (They are not required for Math majors).  My school is pretty famous in Japan, so my boss had very high expectation on me.  And when he found out that I'm virtually useless, he got really really disappointed.  He wanted me to learn all the physics and programming skills in a half year.  However, since I'm not a genius, I failed.  Then he stopped talking to me anymore. So I could have plenty of time spending reading books about programming.

  I've been working in this company about one year.  Now I call myself self-taught programmer.  I read books and Goolge to get knowledge I need.  So far, I've developed one simple heat radiation simulation software using Java and JOGL(JOGL is Java version of OpenGL).  Now, my goal is studying C and CUDA so that I can do some GPGPU.  I'm not sure how far I can go by teaching myself with little help from others.  I don't even know I'm doing it right. But it is fun, so I will keep doing this till I get eventually fired from this company.

  This blog will be my personal diary of what I'm doing at my work, how I feel, and others.