Welcome, Guest. Please login or register.

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

Description:

0 Members and 1 Guest are viewing this topic.

Offline iamaboringperson

  • Hero Member
  • *****
  • Join Date: Jun 2002
  • Posts: 5744
    • Show only replies by iamaboringperson
Re: Beginners 'C' programing group
« Reply #14 on: February 12, 2004, 10:32:47 PM »
I'm sure this would be good for other platforms too.
 

Offline edderkop

  • Jr. Member
  • **
  • Join Date: Mar 2002
  • Posts: 52
    • Show only replies by edderkop
Re: Beginners 'C' programing group
« Reply #15 on: February 12, 2004, 10:39:06 PM »
to get the hello world wrong ?  :-P  what a bummer.

#include

main()
{
  printf("hello world\n");
}

 :-P
Trouble sleeping
Experts recommend that a person with trouble sleeping practice Orc slaying techniques including gut trashing and beheading. These techniques reduce arousal and keep the sleeper’s mind off the sleep problems.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Beginners 'C' programing group
« Reply #16 on: February 12, 2004, 10:59:49 PM »
Right. Here's the correct one:

#include
#include

int main(void)
{
printf("hello world\n");
return EXIT_SUCCESS;
}
 

Offline that_punk_guy

  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 4526
    • Show only replies by that_punk_guy
Re: Beginners 'C' programing group
« Reply #17 on: February 12, 2004, 11:01:47 PM »
Quote

Piru wrote:
Right. Here's the correct one:

#include
#include

int main(void)
{
printf("hello world\n");
return EXIT_SUCCESS;
}


I would have returned zero at the end... bad?
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Beginners 'C' programing group
« Reply #18 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 CaptainHIT

  • Full Member
  • ***
  • Join Date: Jun 2003
  • Posts: 147
  • Country: de
  • Gender: Male
    • Show only replies by CaptainHIT
Re: Beginners 'C' programing group
« Reply #19 on: February 12, 2004, 11:06:48 PM »
Now which one is true? :-)
Or do both work the same? Maybe both work the same, but the later one is just a bit bigger in bytesize only? :-D
Amiga1200 in Ateo Tower, Phase5 Blizzard1260/50MHz, Phase5 SCSI-IV Kit, 64MB Fast-RAM, Elbox Mediator1200, Voodoo3000, SB128, PCI Ethernet Card, 30GB Quantum Fireball & 120GB Seagate Barracuda HDD, 48x24x48x LG CD-RW, 52x LG CD-ROM, Elbox FastATA1200
 

Offline iamaboringperson

  • Hero Member
  • *****
  • Join Date: Jun 2002
  • Posts: 5744
    • Show only replies by iamaboringperson
Re: Beginners 'C' programing group
« Reply #20 on: February 12, 2004, 11:07:26 PM »
what happened to (int argc, char *argv[] ) ?
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Beginners 'C' programing group
« Reply #21 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 iamaboringperson

  • Hero Member
  • *****
  • Join Date: Jun 2002
  • Posts: 5744
    • Show only replies by iamaboringperson
Re: Beginners 'C' programing group
« Reply #22 on: February 12, 2004, 11:14:20 PM »
Quote
To remain compatible, a lot of implementations still allow the original old definition.
(Just to confuse things) Like this: ?

void main(argc,argv)
int argc;
char **argv;
{
...
}

er... if that's how it's done, it's been such a long time since I've programmed that way...


I could be wrong
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Beginners 'C' programing group
« Reply #23 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 iamaboringperson

  • Hero Member
  • *****
  • Join Date: Jun 2002
  • Posts: 5744
    • Show only replies by iamaboringperson
Re: Beginners 'C' programing group
« Reply #24 on: February 12, 2004, 11:23:41 PM »
:lol:
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Beginners 'C' programing group
« Reply #25 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 iamaboringperson

  • Hero Member
  • *****
  • Join Date: Jun 2002
  • Posts: 5744
    • Show only replies by iamaboringperson
Re: Beginners 'C' programing group
« Reply #26 on: February 12, 2004, 11:28:48 PM »
Quote

Karlos wrote:
I havent had to define main in any of my C++ projects for over a year now..

I bet Patrik knows what I mean ;-)
Could mean anything...


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

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Beginners 'C' programing group
« Reply #27 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 iamaboringperson

  • Hero Member
  • *****
  • Join Date: Jun 2002
  • Posts: 5744
    • Show only replies by iamaboringperson
Re: Beginners 'C' programing group
« Reply #28 on: February 12, 2004, 11:37:41 PM »
Quote
Laugh it up mate, laugh it up.
:roflmao:
 

Offline Karlos

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