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??
Printable View
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??
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.
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.
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.
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#.
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.
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.Quote:
They work with the interpreter of the 'Byte Codes' or the "IRL" or whatever it's called.
simply checking the grammer, i think C# and Java are more alike than C or C++.
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.
Again, C# code is not interpreted at any level. Unlike Java by default, the intermediate language is compiled on the host.Quote:
They are compiled into an interpreted binary.
Correct me if I'm wrong but is C# not ran strictly on the .NET framework?
C# was designed specifically for .NET, and other than implementations such as mono which, ignoring specifics, brings .NET to open-source OSs, I have never heard of C# being used to go straight to binary code.
Nor have I. It is a .NET language, and as such is run on the .NET framework. I would say performance-wise .NET has an edge over the Java Virtual Machine, but that wasn't the point. I still prefer Java over C# since sun is nicer about the JVM as opposed to Microsoft who may as well keep .NET inside Fort Knocks.
Java, as it was designed, is an interpreted bytecode. C# is intermediate code, that is compiled at runtime by the .NET Framework.
You may compile both at compilation time using external tools, losing any advantages you had concerning platform independence or hardware specific optimization. No one really wants that.
By that logic, the creators of Mono would by swimming in gold bars by now.Quote:
as opposed to Microsoft who may as well keep .NET inside Fort Knocks.
Once Mono gets powerful enough, I think it should rename their .NET framework for linux to something like ".ORG framework", and then behind the works create the .ORG framework for all operating systems! And then buy out Microsoft and take over the world!
Right... and Christmas isn't just about presents!
Sure bring up mono all the while neglecting how long it took for Microsoft to publically release decent amount of .NET framework specs. I'm sorry but yes I am on the anit-microsoft bandwagen, but at the same time its not for unfounded reasons.
He who laughs last...
http://www.sscli.net