I'm working through C# How to Program Deitel.
They write main as static void.
Based on the C++ standard, is this valid?
Should I not be returning an int to adhear to the os requirement of successful completion of the program??
I'm working through C# How to Program Deitel.
They write main as static void.
Based on the C++ standard, is this valid?
Should I not be returning an int to adhear to the os requirement of successful completion of the program??
"Hence to fight and conquer in all your battles is not supreme excellence;
supreme excellence consists in breaking the enemy's resistance without fighting."
Art of War Sun Tzu
Well remember that C# is a microsoft created language and doesn't have to follow the C++ standard. The best spot to check would be msdn
But is it bad form to have main not return an int in c#.
I understand it is a microsoft derivative of the C family.
But since it is a strain of the C family, should it also have main return an int?
I guess this is a very mundane question, but I just want to make sure my code is correct.
"Hence to fight and conquer in all your battles is not supreme excellence;
supreme excellence consists in breaking the enemy's resistance without fighting."
Art of War Sun Tzu
Without getting into a flame fest over it, C# is about as close as Java is to C/C++
So it reality it doesn't matter what C/C++ says, all that matters is what the C# standard says.
> I'm working through C# How to Program Deitel.
> They write main as static void.
> Based on the C++ standard, is this valid?
Well duh!
C# != C != C++
Surely you don't believe that every language should have an int main. Pascal doesn't follow the C++ standard either.
And no, valid C# programs are in no way valid C++ programs, so the point is moot.
> I understand it is a microsoft derivative of the C family.
No, C# is microsoft java with a new name designed to capture the imagination of a world full of C and C++ programmers as the next best thing to move towards.
ok, that makes since.
I have read in the compiler faq and in this book that it is the evolution of the c family with roots in java and c. but on this forum, everybody openly attacks the idea that it is in relation to either language. That is funny as heck. <<sensorship $ux. thanks for the input thantos.
"Hence to fight and conquer in all your battles is not supreme excellence;
supreme excellence consists in breaking the enemy's resistance without fighting."
Art of War Sun Tzu
wow, sorry to bring that up salem.
I know very little on c#, except what I read on this forum and in the books.
I agree from the syntax I have read, the only thing I find similar are the loops, decision statement, and general non-language specific syntax.
"Hence to fight and conquer in all your battles is not supreme excellence;
supreme excellence consists in breaking the enemy's resistance without fighting."
Art of War Sun Tzu
C# is everything that C++ lacks in RAD features. VB had that, too, but who'd want to admit using VB ?
There is a tool for every job, and C# fits nicely into the client-development role. If I need processing power and fine control I'll use a C++ program, if I need graphics and ease of use, I'll use C#.
hth
-nv
She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."
When in doubt, read the FAQ.
Then ask a smart question.
What nvoigt said is exactly right. Someone jump in here if I'm wrong, but java also uses void main() when exporting code to an exe, correct?
Has no one noticed that both of the languages in question use intermediate languages? They're not compiled all the way, so the operating system does not interface directly with your source code. They work with the interpreter of the 'Byte Codes' or the "IRL" or whatever it's called. This could very well be the reason for voiding main.
I don't think it as anything to do with that. If you want to return anything to teh OS in java, just use System.exit( code );
The reason is that most programs (especially GUI) don't use the return code and it is cumbersome to always add a return statement to your program. C++ solves this by adding an implicit return 0 if no return statement is specified, but that is a hack.
The programs that wish to return something just use System.exit.
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
C# Code is not interpreted. The Intermediate assembly language is compiled at the client side just in time. There are also tools that compile immediatly. But that is giving away the possibility to optimize for the client computers hardware.They work with the interpreter of the 'Byte Codes' or the "IRL" or whatever it's called.
hth
-nv
She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."
When in doubt, read the FAQ.
Then ask a smart question.
simply checking the grammer, i think C# and Java are more alike than C or C++.
Never end on learning~
Java/C# are what I call the gray area languages. They are compiled into an interpreted binary. Thus its capable of running faster than lets say a Python script, but is still ultimately being run by another program that interprets its code. I wouldn't quite call them an interpreted languages in the more conventional "scripting language" sort of way, but they are interpreted no less.