Author Topic: C Programming from literally thr ground up  (Read 1146 times)

Calum

  • Global Moderator
  • Member
  • ***
  • Posts: 7,812
  • Kudos: 1000
    • Calum Carlyle's music
C Programming from literally thr ground up
« on: 15 July 2002, 03:19 »
So, i am literally at the 'hello, world' stage, and my book says that to use printf, i need to declare stdio.h which i understand of course, well i being me, went and did 'less /usr/include/stdio.h' to see what the magical defenitions were that miraculously allowed me to use the printf function, and of course could not understand a word!

What are the headers themselves written in? and since they are text (seemingly) is it possible for some headers be closed source?

I know i should get more into it but you know, always inquisitive. ANd i will be getting more into it anyway, just nosy really!

[ July 14, 2002: Message edited by: Calum ]

visit these websites and make yourself happy forever:
It's my music! | My music on MySpace | Integrational Polytheism

TheQuirk

  • VIP
  • Member
  • ***
  • Posts: 2,154
  • Kudos: 315
C Programming from literally thr ground up
« Reply #1 on: 15 July 2002, 03:24 »
All of the headers I used are always "open" to view. I'm sure someone else here could give a better answer, because I can't (i'm not sure myself.)

jtpenrod

  • VIP
  • Member
  • ***
  • Posts: 675
  • Kudos: 105
C Programming from literally thr ground up
« Reply #2 on: 15 July 2002, 07:43 »
quote:
/* Define ISO C stdio on top of C++ iostreams.
   Copyright (C) 1991, 1994-1999, 2000, 2001 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */
Here is the beginning of stdio.h. As you can see, it most definitely is not closed source. What this file contains are simply the usual C-type forward declarations with some compiler conditionals that may or may not be included, depending upon what system it's being run on and what features it supports. It might seem all a bit arcane right now, but there really isn't anything too out of the ordinary there. Of course, stdio.h itself depends upon three other files: stddef.h, features.h, and bits/types.h.
Code: [Select]
Here is the part that allows printf to work. This forward declairs a function, printf, that returns an integer to the calling routine. Since it's declaired to be an "extern", the compiler will look in other files for the actual definition and implementation of printf. "__THROW" is a macro for error handling should something go wrong and printf can't execute. Of course, being at the "Hello World!" stage, there's no way you'd be expected to know all this just yet. Keep at it, and all will become clear.
_______________________________________

Live Free or Die: Linux

"There: now you'll never have to look at those dirty Windows anymore"  --  Daffy Duck  :D
Live Free or Die: Linux
If software can be free, why can't dolphins?

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
C Programming from literally thr ground up
« Reply #3 on: 15 July 2002, 07:54 »
stdio.h is C source code. "headers" are really nothing more than prototype declarations for functions contained in libraries (and more). The printf() function is actually contained in /usr/lib/libc.a (static library) and /lib/libc.so.6 (dynamic library). Those libraries are binary (compiled). The benefit you get from linking your code to these libraries is so you don't have to recompile each and every standard function every time you compile a program (saves MUCH time).  If you want to see what the actual "printf()" function code looks like you will have to get the libc source code (there is an RPM for it).  There will probably be a "printf.c" file included in there. "libc" contains most of your basic standard C functions.

Does that help any?
Someone please remove this account. Thanks...

TheQuirk

  • VIP
  • Member
  • ***
  • Posts: 2,154
  • Kudos: 315
C Programming from literally thr ground up
« Reply #4 on: 15 July 2002, 11:21 »
what I'm intrested is (it seems to relate to this) if there are headers that we use that AREN'T under the GNU?

badkarma

  • VIP
  • Member
  • ***
  • Posts: 497
  • Kudos: 0
C Programming from literally thr ground up
« Reply #5 on: 15 July 2002, 14:33 »
there's no such thing as a closed source header (even with a closed source library, the header is *allways* available)

the implementation can be closed source though (but you won't see any closed source libraries in most (all?) linux distributions)
If you can't learn to do something well, learn to enjoy doing it poorly.

TheQuirk

  • VIP
  • Member
  • ***
  • Posts: 2,154
  • Kudos: 315
C Programming from literally thr ground up
« Reply #6 on: 15 July 2002, 23:51 »
I understand you can see their content, but are there any ones that are illegal to look at?

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
C Programming from literally thr ground up
« Reply #7 on: 16 July 2002, 00:29 »
Heh heh, not hardly.  If they were illegal to look at they would not be included. *.c and *.h files are "source" code.  If you have binaries there is no need for *.c and *.h files.
Someone please remove this account. Thanks...

badkarma

  • VIP
  • Member
  • ***
  • Posts: 497
  • Kudos: 0
C Programming from literally thr ground up
« Reply #8 on: 16 July 2002, 13:13 »
if you have binaries, and it's a development library, you do have *.h files, when it's closed source you don't have *.c files though (so you can see all function definitions and use those functions in your code, however you cannot see the implementation of said functions)

to get back to the original topic:

Calum ... skip C and learn C++, it's a much cleaner programming language (and it's a bit harder to learn C++ if you're in a C mindset (the basics are the same, but C++ uses a lot of different programming idioms)

in the case of your hello world program there would only be minute differences:

in C:

Code: [Select]

in C++:

Code: [Select]

and the nice way of doing it in C++:

Code: [Select]

[ July 16, 2002: Message edited by: BadKarma ]

If you can't learn to do something well, learn to enjoy doing it poorly.

KernelPanic

  • VIP
  • Member
  • ***
  • Posts: 1,878
  • Kudos: 222
C Programming from literally thr ground up
« Reply #9 on: 16 July 2002, 14:28 »
I agree with BadKarma C++ is better.
Contains scenes of mild peril.

the_black_angel

  • Member
  • **
  • Posts: 82
  • Kudos: 0
C Programming from literally thr ground up
« Reply #10 on: 16 July 2002, 15:23 »
I agree learn C++

A good online tutorial is available at www.cprogramming.com

i wanted to learn how to Program JAVA but all the tutorials i found refered back to C/C++ and where really confusing so i am going to learn C++ first.

C++ is suppoed to be much more secure than C as well
--
The Black Angel

Calum

  • Global Moderator
  • Member
  • ***
  • Posts: 7,812
  • Kudos: 1000
    • Calum Carlyle's music
C Programming from literally thr ground up
« Reply #11 on: 16 July 2002, 17:07 »
yeah, but i have C books, so i'll learn a bit of it first i think...

how is C implemented in windows? is there a lot of different stuff you need to put in?

just curious, there's no need for me to ever use windows for programming.
visit these websites and make yourself happy forever:
It's my music! | My music on MySpace | Integrational Polytheism

KernelPanic

  • VIP
  • Member
  • ***
  • Posts: 1,878
  • Kudos: 222
C Programming from literally thr ground up
« Reply #12 on: 16 July 2002, 17:41 »
What do you mean by 'implemented'?
Contains scenes of mild peril.

Calum

  • Global Moderator
  • Member
  • ***
  • Posts: 7,812
  • Kudos: 1000
    • Calum Carlyle's music
C Programming from literally thr ground up
« Reply #13 on: 16 July 2002, 19:23 »
well i mean c is a unix programming language but seems to be able to compile in windows, yes? how do they compensate for the different directory structure, different gui and so on?
visit these websites and make yourself happy forever:
It's my music! | My music on MySpace | Integrational Polytheism

badkarma

  • VIP
  • Member
  • ***
  • Posts: 497
  • Kudos: 0
C Programming from literally thr ground up
« Reply #14 on: 16 July 2002, 19:39 »
there is no such thing as a "unix" programming language ... a programming language is not OS dependant (I'm dutch ... does that mean I allways and only have to/can speak dutch?  :D )
If you can't learn to do something well, learn to enjoy doing it poorly.