learning C (53)

1 Name: #!usr/bin/anon 2005-04-11 11:42 ID:CwnpYNPT

could someone suggest good place to learn C ? or maybe i should go with C++ ? i know some other languages ( Ruby, PHP, OCaml, Smalltalk, Delphi, C#, VB... ) so no need for tutorials that explain what is variable and how to use 'if' and such...

2 Name: !WAHa.06x36 2005-04-11 12:08 ID:3WfI3O5K

Might be good to learn C first. C++ is admittedly a bit of a mess, and it might be easier to find your way around if you know C first.

Out of the languages you mentioned, PHP and C# are probably closest, syntax-wise. It's been a long time since I learned it and I just picked up a book at random and read it, so I don't have much good advice for where to learn it. I can point out the things you might want to look at, though:

  • C is fairly strongly typed (although it auto-converts between different types of integers and floats), and I think it is quite similar to C# in that. Variables are only declared at the start of blocks, not in the middle of them (unless you're using C99). C only has functions and no objects. Functions are often declared in a header file with a function prototype.
  • On that note, look into how C include files are built, and how the preprocessor works (#include, #define, #ifndef and so on).
  • Pointers are strange and scary to people not used to them. Look into pointer arithmetic, and the differences and similarities between arrays and pointers (arrays behave much like pointers in most contexts, but arrays have a block of memory associated with them while a pointer can be pointed to whichever block you want). Also, neither arrays nor pointers have any kind of bounds checking, so you can easily overwrite random bits of memory. Be careful with that.
  • structs are compound datatypes much like objects in other languages, but without any methods. Pass-by-reference is popular in other languages, and in C the equivalent is to pass pointers to structs. You can, however, also pass structs themselves, which amounts to copying the contents of the struct.

Well, those are some random unorganized thoughts. Have fun!

3 Name: #!usr/bin/anon 2005-04-13 19:53 ID:b4WVx85q

thanks man... just finished reading Introductory Class Notes ( http://www.eskimo.com/~scs/cclass/notes/ ) which did explain most of that stuff you mentioned now to Intermediate Class Notes ( http://www.eskimo.com/~scs/cclass/int/ ) anything else i should keep eyes open for ? and i was wondering about what magic you need to set up things so that you could ./configure && make && make install ?

4 Name: dmpk2k!hinhT6kz2E 2005-04-13 20:08 ID:oJqfGRBU

5 Name: !WAHa.06x36 2005-04-14 14:35 ID:yjE4KM2t

Makefiles are deep magic, and autoconf I've never dared go near. Make is mostly independent from C, though, so you can just ignore it if you want, and build things by hand. When your source grows beyond a couple of files, though, you may want to learn how to use it.

6 Name: Mr VacBob!JqK7T7zan. 2005-04-14 22:09 ID:47ZsLO2t

autoconf and automake are at least easier to write than handmade Makefiles.
Quick Guide off the top of my head:

  • type into Makefile.am in the same directory as the source

bin_PROGRAMS = <program name>

<program name>_SOURCES = <source .c .h and other files>

That assumes you already have everything installed, though.

7 Name: !WAHa.06x36 2005-04-15 13:46 ID:yjE4KM2t

I don't like autoconf, though, because if you use it, you instantly limit yourself to POSIX systems. If you're writing just ANSI C without any deeper hooks into the system, you're better off staying away from autoconf.

8 Name: Mr VacBob!JqK7T7zan. 2005-04-16 04:11 ID:axU2aG+k

The usual approach to that is to also include a CodeWarrior or MPW or Visual C++ or Xcode or whatever crazy project file along with it, as well as a handmade config.h or whatever else the autoconf scripts would usually generate to go with it.

9 Name: !WAHa.06x36 2005-04-16 19:39 ID:vN3awgV+

>>8

Except nobody does. Autoconf is fine (ok, it's a kludge for a kludge for a kludge, but it sort of works) for projects that are heavily Unix-dependent, but when simple command-line programs, or even worse, libraries use it, I feel ANGER.

10 Name: #!usr/bin/anon 2005-04-17 21:09 ID:gHzGuaEH

Unless you're writing something which has serious POSIX portability problems, or which uses metric assloads of different libraries, Autoconf is overcomplex, the proverbial artillery instead of a flyswatter. Simple programs that don't need wads of different libraries or don't depend on nonstandard C library extensions should just have a simple makefile which has targets for "all", "test", "clean", and maybe "depend" if it has funny header dependencies.

11 Name: #!usr/bin/anon 2005-04-17 21:11 ID:gHzGuaEH

Learning to use make is actually pretty simple. Check out the O'Reilly book on make, which gives excellent tutorials. Also check out the makefile for simple programs that don't use Autoconf. The makefiles generated by Autoconf are insanely complex, and hard for mere mortals to understand.

12 Name: Mr VacBob!JqK7T7zan. 2005-04-18 16:45 ID:CD+GtLf7

>>9

I'd prefer autotools to having to rewrite the build script to use OS X shared library flags with cc instead of Linux's.

13 Name: Mr VacBob!JqK7T7zan. 2005-04-18 16:47 ID:kSDfwFTF

That was for libraries, I mean. I don't care much about simple programs, and I'm certainly not going to add autoconf to tripper2ch. Even though part of it doesn't compile on glibc anymore.

14 Name: #!usr/bin/anon 2005-04-18 21:02 ID:UTX3Mrpi

I'd prefer that Apple hadn't felt the need to swap a perfectly good, widely accepted two-letter extension with a five-letter one and break a considerable amount of POSIX source packages, including some that do in fact use use autotools.

Though, you usually need to hack the build script anyway due to their fucked up libtool.

15 Name: Mr VacBob!JqK7T7zan. 2005-04-18 21:08 ID:xSDmY8sd

.dylib was inherited from NeXT.

16 Name: BRAF!8NBuQ4l6uQ 2005-05-30 23:23 ID:k8JsSYdy

17 Name: #!usr/bin/anon 2005-05-31 06:58 ID:Heaven

>>16
That's just a BSD fanboy having a cry because things are different and because Apple target towards normal desktop users first, rather than developers wanting everything free, opensource with code provided.

18 Name: Mr VacBob!JqK7T7zan. 2005-06-05 02:45 ID:s299fVPf

My favorite part is how he complains about how OS X is annoying and then goes back to OpenBSD, of all things.

local wString
set wString to "("
repeat 128 times

set wString to (wString & "w")

end repeat
display dialog wString

19 Name: Mr VacBob!JqK7T7zan. 2005-06-05 02:47 ID:s299fVPf

WakabaMark screwed up my beautifully indented AppleScript :(

20 Name: #!usr/bin/anon 2005-06-05 10:26 ID:mSoBitPK

WakabaMark is evil :/

21 Name: !WAHa.06x36 2005-06-05 12:19 ID:vN3awgV+

Indent code by four spaces or one tab. It's not like you could make indented code in plain HTML text anyway without somehow adding a <pre> block.

22 Name: Furi!EuK0M02kkg 2005-06-27 15:35 ID:Heaven

>>1
Everything Waha said in >>2, signed.
If you can find it, I believe K&R's The C Programming Language (title?) is a good read.

Closing thoughts. Pointers and structs are "fun". :)

23 Name: A User 2005-07-21 08:53 ID:huFbmIn+

For those complaining about OSX and OpenBSD.... would you rather have M$ WinBlow$?

By the way... I'm a user.... of what??

24 Name: dmpk2k!hinhT6kz2E 2005-07-21 11:35 ID:Heaven

I'd rather have Windows if the only choice was between that and OpenBSD, at least for a machine that isn't a server. If I need a unix environment, I can always SSH into it.

25 Name: dmpk2k!hinhT6kz2E 2005-07-21 11:42 ID:Heaven

>>22
Pointers can be a nuisance, but structs are one of the things I particularly liked about C.

26 Name: #!usr/bin/anon 2005-07-21 13:14 ID:Heaven

>>23

"M$ WinBlow$"? What are you, fourteen years old?

27 Name: #!usr/bin/anon 2005-07-25 02:34 ID:Heaven

Just sticking it to "the man" or something. Whatever.

28 Name: #!usr/bin/anon 2005-08-06 16:56 ID:+oZjjyYZ

#include <stdio.h>

void main() {
printf("Hello world");
}

I think this is the best start :P
compile it with GNU

29 Name: rickyok 2005-08-06 16:59 ID:+oZjjyYZ

If you want to learn PHP

Try download the manual of PHP from
http://www.php.net/ I learned of all my skill from those manuals
http://www.apache.org/ for the server
and http://www.mysql.com/ for the database :P

30 Name: Furi!EuK0M02kkg 2005-08-06 17:33 ID:Heaven

>>29
No! "The database" as you call it, must be www.postgresql.org
For great justice! :)

31 Name: !WAHa.06x36 2005-08-06 19:37 ID:Heaven

> If you want to learn PHP

Why on earth would you want anything like that? Especially in a thread about learning a real programming language? <-- troll

32 Name: rickyok 2005-08-07 16:37 ID:9TRJ/5qy

Ah, i missread that He already can use php , hehee, pardon me

33 Name: #!usr/bin/anon 2005-09-11 00:53 ID:5aRPR0II

MOE-C

ttp://moe-c.chu.jp/main.html

oh, it burns it burns

34 Name: Albright 2005-09-11 12:15 ID:Heaven

ttp phaggotry fixed: http://moe-c.chu.jp/main.html

What exactly am I looking at?

35 Name: #!/usr/bin/anonymous : 2006-07-20 15:29 ID:Heaven

>>28
Bonehead.

36 Name: #!/usr/bin/anonymous : 2008-03-02 23:53 ID:cYu0GLeg

never gets old

37 Name: #!/usr/bin/anonymous : 2008-03-14 16:48 ID:uh2i3Aaa

C is so old.
Isn't the rest of the world using D, E or even F now?

38 Name: #!/usr/bin/anonymous : 2008-03-16 11:53 ID:Heaven

I know about D (and love it) but is there a viable E or F?

39 Name: #!/usr/bin/anonymous : 2008-03-16 14:06 ID:Heaven

>>38
I don't know about E, but he probably means F# with F;
F# is a terrible language.
As for D, the language itself is not that bad, but the implementation is horrible.
C++ is not that bad, I prefer it than D.

40 Name: #!/usr/bin/anonymous : 2008-03-16 15:10 ID:Heaven

> F# is a terrible language.

Because it's made by Microsoft?

41 Name: dmpk2k!hinhT6kz2E : 2008-03-16 15:41 ID:Heaven

> the implementation is horrible.

Elaborate a bit on that?

> F# is a terrible language.

Hopefully it's not too close a copy of Ocaml. I'm still pissed off over the single namespace for record field names.

42 Name: #!/usr/bin/anonymous : 2008-03-17 13:06 ID:Heaven

>>40
No. Because it is.
But wait, do you have anything to actually support F# or are you one of these fools that like to argue with MS haters?
Stop trying to save MS, what MS writes is *usually* horrible.
They steal a *lot* of code from open source projects, they are shitheads and try to make their competitors look bad (google Samizdat: And Other Issues Regarding the 'Source' of Open Source Code, total BS written by a slimeball who was funded (along with his institute) by MS to write the book)
You are still not convinced? MS threatened to sue linux because they found .. stolen code in the linux kernel.
They ofcourse did that to scare companies that wanted to use linux as servers, because they also threatened they'd sue companies that use linux.
Ofcourse, the linux community asked for the code that's in the windows kernel that was stolen and MS shutted the fuck up.
Oh, you still are not convinced? Earlier kernels of Windows used the (under BSD licence) TCP/IP implementation from BSD.
This can easily be seen in a simple packet capture session.
You are still not convinced microsoft sucks? Look at all the exploits they have for their products WITHOUT even releasing the source.

No, F# doesn't suck because of MS. It sucks because it was designed by idiots.
I'm not an MS hater, in fact, I despise both sides; those who hate MS (which is ridiculous considering MS is just a company that wants to make money, like so many other companies) but I also hate those like you. The type of guy "Oh because it's made by MS right? Eh MS hater? Yeah, what do you know!?! Let's all blame MS because we are jealous BAWWW". NO. NO. FUCK. YOU.

>>41
Memory leaks everywhere, static ifs and other hacks because they failed to write a proper implementation. I could go on but read about these first.

43 Name: #!/usr/bin/anonymous : 2008-03-17 13:41 ID:iiXynYzy

E was on Amiga.

44 Name: #!/usr/bin/anonymous : 2008-03-17 14:56 ID:ymzyiJ4o

>>42
Wow... lay off the crack.

I must admit I didn't quite follow the entirety of your drooling rant, but I feel I should clear up a couple of your baseless accusations.

First, it's perfectly legal for MS to use BSD socket code, and they even complied with the advertising clause, crediting the Regents of the University of California as they were required. You don't need to capture packets to know that. And consider this: had Microsoft *not* used the BSD socket library, where do you think computer networking would be today? Take a look at this essay.

Second, of *course* they try to make their competitors look bad. It's not like that's something only MS has ever done. Take a look at some Apple commercials: "I'm a Mac, and I'm a PC." In fact, try watching commercials for just about any product. There's usually two themes in play: make their product look desirable, and make competing products look undesirable. It's certainly not something unique to Microsoft.

45 Name: #!/usr/bin/anonymous : 2008-03-17 16:05 ID:b6MpoPPc

>>44
Look, my point was just that F# is bad.
The rest.. I had my feelings to get the better of me.
I strongly suggest that >>40 is a faggot.

46 Name: #!/usr/bin/anonymous : 2008-03-18 02:31 ID:Heaven

I interpreted >>40 as a guess that perhaps >>39 considered F# to be terrible because of its origin, not that >>40 believed that.

47 Name: #!/usr/bin/anonymous : 2008-03-18 02:31 ID:Heaven

I interpreted >>40 as a guess that perhaps >>39 considered F# to be terrible because of its origin, not that >>40 believed that.

48 Name: #!/usr/bin/anonymous : 2008-03-18 02:31 ID:Heaven

Lol whoops, I suck.

49 Name: #!/usr/bin/anonymous : 2008-03-18 12:30 ID:eWkv9QxY

>>45

F# is simply an ML variant. ML is fairly well-regarded among functional programmers as far as I know. I have not heard anybody who actually knows anything about the matter say F# is a particularly bad language.

The people who do say it is, however, are the kind of people who go on long, badly spelled, incoherent rants about how Microsoft is EVIL AND MUST BE STOPPED, which are full of errors and outright lies.

>>46-48

You were wrong.

50 Name: >>45 : 2008-03-18 12:33 ID:b6MpoPPc

>>49
Look buddy, you are out of your league. Step back.
You really don't want to get me angry on this issue.

51 Name: #!/usr/bin/anonymous : 2008-03-18 18:22 ID:Heaven

>>50

Perhaps you should get some therapy for those anger issues.

52 Name: #!/usr/bin/anonymous : 2008-03-19 00:37 ID:Heaven

>>50
Or what?

53 Name: #!/usr/bin/anonymous : 2008-03-19 01:28 ID:Heaven

>>52

We wouldn't like him when he's angry.

Name: Link:
Leave these fields empty (spam trap):
More options...
Verification: