Welcome, Guest. Please login or register.

Author Topic: Beginners 'C' programing group  (Read 13090 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Beginners 'C' programing group
« on: February 12, 2004, 10:14:55 PM »
@thread

Good luck with the learning. I applaud you choice of language. Contrary to most people's initial experience, C is actually quite logical and easy to learn once you get to grips with the syntax.

I wish I could devote some time for something like this, but I wish you all well.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Beginners 'C' programing group
« Reply #1 on: February 12, 2004, 11:03:22 PM »
@tpg

No. EXIT_SUCCESS is technically implementation defined but is pretty much zero everywhere.

-edit-

That's no as in its not especially bad ;-)
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Beginners 'C' programing group
« Reply #2 on: February 12, 2004, 11:09:39 PM »
One thing about C is that its definition of the main function has become fudged over time.

Originally, main was defined thus:

main()

As time went on, C got a bit stricter with its function definitions and main, which technically returns an integer was redefined to explicitly show this

int main(void) - used when no start parameters are used, or

int main(int argc, char** argv) - used when you want to access whatever was passed on the command line.

To remain compatible, a lot of implementations still allow the original old definition.

The best advice. Use an up do date C compiler and use explicit integer return type definition of main (ie either of the second two above).
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Beginners 'C' programing group
« Reply #3 on: February 12, 2004, 11:20:39 PM »
@iama

If you code that with ANSI rules enabled it will fart at you and say K&R syntax is depricated ;-)
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Beginners 'C' programing group
« Reply #4 on: February 12, 2004, 11:26:37 PM »
I havent had to define main in any of my C++ projects for over a year now..

I bet Patrik knows what I mean ;-)

-edit-

Better stop before I drag the thing totally off topic!
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Beginners 'C' programing group
« Reply #5 on: February 12, 2004, 11:32:36 PM »
Quote

iamaboringperson wrote:
You've been working on the same projects for over a year? :lol:


Laugh it up mate, laugh it up. I moved on to Application class based coding ages ago. I havent defined main() in any projects started in the last year as I havent needed to :-P
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Beginners 'C' programing group
« Reply #6 on: February 12, 2004, 11:48:30 PM »
I guess he did, too :-)
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Beginners 'C' programing group
« Reply #7 on: February 13, 2004, 12:40:40 AM »
@thread

Sorry, going off topic...

@BigBenAussie

I have been developing a cross platform C++ class library for rapid application (specifically game/multimedia) development.

Presently it is only amigaos implementation level, but it none of the classes expose system level stuff. It handles kernel services, io, gfx, sound, etc. via a set of interfaces and wrappers.

It took 10 mins to write this silly goo clone using these class libraries in their current state.

If c++ is your thing, the source for the above program (but not the class libraries themselves ;-) ) is all here.

(I use a tab of 2 spaces if the source looks screwy)
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Beginners 'C' programing group
« Reply #8 on: February 13, 2004, 01:21:36 AM »
@BigBenAussie

The library actually a set of abstractions comprising a complete framework, not just 3D. Also, it's not for newbies, its for experienced lazy b*stards...

Hence the "off topic" remark ;-)
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Beginners 'C' programing group
« Reply #9 on: February 13, 2004, 01:41:42 AM »
Perhaps to avoid off topic discussion and trolling?

I'm not saying it will definately happen, but you know how it is when people think their solution (and I am as guilty of this as anybody) is better than someone elses and a perfectly simple question gets dragged into a long discussion going way off topic...

...like I am now :lol:
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Beginners 'C' programing group
« Reply #10 on: February 13, 2004, 01:47:34 AM »
Quote

that_punk_guy wrote:
(Wonder what Cyberus will be able to read into that comment?)


Everything.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Beginners 'C' programing group
« Reply #11 on: February 13, 2004, 02:13:25 AM »
@red

There is a tutorial forum already, right? You could create a C Tutor forum in there with some stricter moderation and various people on hand to answer questions. You'd need to keep an eye on the level of discussion some answers can generate, 'experts talking shop' can go off topic quickly, leaving the person asking the question more confused than before they asked.

Judging when people are going down this route as opposed to genuinely answering questions to the best of their abilites will be the tricky part, IMO.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Beginners 'C' programing group
« Reply #12 on: February 13, 2004, 11:02:39 AM »
Quote

FluffyMcDeath wrote:

That's mighty pretty, Karlos, but I must quibble.
in:
if (thing) delete thing;

The test is redundant (delete NULL is safe).

if(!thing)
{
    errorPopUpThingy("failed to alloc thing");
}

won't ever happen unless you use operator new(no_throw)
else new throws bad_alloc which you'll need to catch.


@Fluffy

You are absolutely correct about the no_throw, but I'm afraid you are assuming too much.

-edit-
Is it me, or does the above sound like it should have been wrapped in a sort of typical "James Bond villian" tag? :-)
-/edit-

Part of the reason the framework itself isn't pulbic yet is that it was written in that 'less than stellar c++' compiler, StormC.

Exceptions are not used by any of the components because I discovered early on that the exception mechanism in storm is  broken.

Its fine in single thread programs, but the framework defines a Threadable service class (kind of like a fusion of java Thread and java Runnable interface) that allows the class inhertiting the service to have its own internal thread of execution.

I discovered that in multithreaded code, the thread which throws an exception is hardly ever the one to catch it. That is, StrormC's implememntation doesn't do the book keeping.

StormC, even with exceptions enabled doesn't support new(no_throw) in any case, nor does it safely check the null pointer case for delete.

Basically any oddities you see are all down to the fact that I started in StormC++ which was a mistake.

The whole framework code will be moved to gcc which will hopefully not be too much of a problem since I don't use any storm dependent features (other than the ide). Some asm code exists in places (optimised versions of various methods).

Post gcc plans are to use proper exception based error handling (to replace the existing return value model) and probably some namespace resolution for libraries.

First things first, the code will be ported as is. Then exception handling introduced to replace the existing error returns (in places where a genuine error exists, rather than something better represented by a bool return etc.).

The gcc port will also make the cross platform coding a lot easier. Currently the windohs version is maintained in open watcom....
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Beginners 'C' programing group
« Reply #13 on: February 13, 2004, 12:35:12 PM »
@Cymric

I tend to agree. C is the starting point for someone new.

You need to know C syntax, functions and structures before you have the knowledge base to truly take in what a class is. That's before you get into stuff like overloading, generic programming etc.

One of the things which Bjarne Stroutsrup himself notes in his C++ Language book is that "a good C program is also a good C++ program."
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Beginners 'C' programing group
« Reply #14 on: February 13, 2004, 12:47:36 PM »
@mikeymike

You'd be surprised for a "high level" language how low level C really is. Its much lower level than BASIC type languages and as a compiled language it is faster mostly due to the fact that it is quite close to the machine level already.

The beauty of C is that it gives you high level abstractions for things which are a pain (and non portable) to do in asm, without really being much higher.
int p; // A