LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-04-2003, 03:21 PM   #1
linuxanswer
Member
 
Registered: Oct 2003
Distribution: woodY 3.0 stable
Posts: 61

Rep: Reputation: 15
define main


can ia define main like this

main(int, *char)
 
Old 11-04-2003, 03:33 PM   #2
LogicG8
Member
 
Registered: Jun 2003
Location: Long Island, NY
Distribution: Gentoo Unstable (what a misnomer)
Posts: 380

Rep: Reputation: 30
Yes, approximately

Code:
main (int a, char *arg)
{
        return 0;
}
is a legitamate program that will compile
with no warnings (unless you use -Wall)

Mind if I ask why you want to declare main that way?
 
Old 11-04-2003, 03:35 PM   #3
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
That would be a prototype. By convention, main is already "defined",
and depending on how close to ANSI C you set the compilation options
you may or may not get errors.

The standard way to do main is
Code:
int main(int argc, char *argv[]){

      return 0;
}
You really should consider this to be THE way to write main().
Some early DOS compilers like Turbo C would actually complain if you did not use argc and argv in your code and you declared them as main() arguments like above. Which IMO is nonsense.

Some compilers will let you do:
Code:
 void main(void){
}
Generally, you want you code to return success/failure to the shell, so this is not a great idea.
 
Old 11-04-2003, 03:35 PM   #4
linuxanswer
Member
 
Registered: Oct 2003
Distribution: woodY 3.0 stable
Posts: 61

Original Poster
Rep: Reputation: 15
i don't know, it's curiosity
 
Old 11-04-2003, 03:38 PM   #5
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Think of it this way:
Just because you can take a pistol and shoot off your big toe doesn't mean that you should.

Same thing in programming. Maybe it's nice to know, but you don't need to shoot yourself in the foot just because you can.
 
Old 11-04-2003, 04:17 PM   #6
LogicG8
Member
 
Registered: Jun 2003
Location: Long Island, NY
Distribution: Gentoo Unstable (what a misnomer)
Posts: 380

Rep: Reputation: 30
This link is now obligatory.
http://burks.brighton.ac.uk/burks/language/shoot.htm
 
Old 11-04-2003, 04:21 PM   #7
jhorvath
Member
 
Registered: Sep 2002
Location: OH, USA
Distribution: 2.6.16-1.2096_FC5 #1
Posts: 245

Rep: Reputation: 30
that's awesome
 
Old 11-05-2003, 08:30 AM   #8
Kurt M. Weber
Member
 
Registered: Oct 2003
Distribution: Slackware
Posts: 335

Rep: Reputation: 36
Also, I should point out that given the way the question was phrased, the only possible answer is "yes"

You CAN do whatever the hell you want...whether it works or not is a different question entirely
 
Old 11-05-2003, 02:02 PM   #9
jhorvath
Member
 
Registered: Sep 2002
Location: OH, USA
Distribution: 2.6.16-1.2096_FC5 #1
Posts: 245

Rep: Reputation: 30
Quote:
You CAN do whatever the hell you want...whether it works or not is a different question entirely
i'm going to go ahead and second mr. Weber on that
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Best way to define variables? Yig Linux - Software 3 08-24-2005 05:09 PM
C++ question #define ... Bluesuperman Programming 4 02-01-2005 09:49 AM
size of define cynthia Programming 2 09-22-2004 08:56 AM
define jhon Linux - Networking 2 08-30-2004 07:42 PM
using #define Jo_Nak Programming 4 06-11-2003 01:46 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration