Help me understand flow in C apps

This is a discussion on Help me understand flow in C apps within the C Programming forums, part of the General Programming Boards category; I come from an object oriented environment, so not having objects really confuses me with C. I see structs a ...

  1. #1
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438

    Help me understand flow in C apps

    I come from an object oriented environment, so not having objects really confuses me with C. I see structs a lot, which look very similar to objects (minus the methods). Would this be "objects" in C?

    So basically in C, you have a main method which calls functions from other source files through headers? I imagine it must be more advanced than that. I wonder how something like the linux kernel actually works. I've got the source, but it's not exactly easy to figure out where to start.

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    A C struct is not really an object. An object is an instance of a class and a class is an abstract datastructure. Abstract datastructures consist of data and functions operating on it.

    You can do object oriented programming in C. Then you would have to define such an abstract datastructure. This would mean that you define some datastructure and write functions which operate on it. These functions can be divided into two kinds, private functions and public functions. The public functions are those which are used by applications which make use of the abstract datastructure and the private functions are used within the abstract datastructure.

    In C there is a main method, just the same as in C++, Java, Pascal and other languages. This function, called main(), is the entry point of your program. The function calls other functions, which in turn can call subfunctions, which can call other functions etc. These functions are stored somewhere in your object files, which are the result of the compilation process. The header files are only used by the compiler to get knowledge about used datastructures and functions. The linker links the object files together and so creates the application.

  3. #3
    sockets mad
    Join Date
    Mar 2002
    Posts
    126
    structs are not objects in C. The C language does not natively support object orientated programming.

    However, the C++ language has very advanced OOP capabilities through the use of classes. My advice is get hold of a good C++ book, there's a huge amount to learn

    Be careful when you call functions like main() a method. Functions are only methods when they are implemented as member function of an object. On their own, they are simply functions.

    Include files are basically normal C/C++ files which contain declarations of variables, objects and functions (among other things), whether they are in another C/C++ file or a pre-compiled library. You are correct in what you said, but it is, as always, more complicated than that

    And if you're just starting to learn, I wouldn't say the Linux kernel is the best example to refer to

    Dan
    Last edited by codec; 04-04-2004 at 01:21 AM.

  4. #4
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    Thanks for both replies. I understand all you guys have said. I guess I should have said I'm not a complete newb, I just have a hard time getting the "object" feel in basic C. The reason I ask is because I've been getting into Linux a lot lately and C looks like a great language to use. I've used C++ more and it seems a lot easier coming from a Java and C# background.

  5. #5
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    Nice to hear from some one who started to program using OOP's.. most of us started out with Procedural and moved on to OOP's.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows apps verses Console apps
    By nano78 in forum Windows Programming
    Replies: 8
    Last Post: 09-22-2007, 04:41 AM
  2. debugging directx apps
    By confuted in forum C++ Programming
    Replies: 1
    Last Post: 08-16-2003, 09:56 AM
  3. Beginner on Win32 apps, lame question.
    By Templario in forum C Programming
    Replies: 3
    Last Post: 11-06-2002, 08:39 PM
  4. graphics in c/c++ console apps
    By anthonye in forum C Programming
    Replies: 2
    Last Post: 06-20-2002, 06:39 AM
  5. My opinion on visual apps
    By valar_king in forum Windows Programming
    Replies: 15
    Last Post: 10-08-2001, 06:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21