![]() |
|
#1
|
|||
|
|||
Argc, Argv[] and Command LineHi all,
Question 1: i was reading some documents online, i have encountred this statement int main(argc, argv[]) and the topic was reffering to command line so i did not know what is command line arguments and the argc, argv[] (please if anyone can help with defining these terms and why arv[] has the brackets like an array? Question 2: Does anyone know what is the void type i ve seen this before int funct(void *) : so i said what a newbi will do with that? Please if you can provide an example implementing a response to the 2 questions that will be appreciated ? |
|||
|
#2
|
||||
|
||||
Re: Argc, Argv[] and Command LineQuote:
CPP / C++ / C Code:
Output: Code:
argc is an integer count of the arguments given on the command line when invoking the program. The "c" part is count of the "arg" part which is argument(s). argv[] is a variable length (the "v" part) array that is created at runtime based on the command line invocation. It is an array of char pointers whose number (count) of elements is exactly argc. Note that the program name passed to the loader is always the first (zeroth index of the argv array) argument. Quote:
...probably screw it up. The "void" type is "typeless." In C, it is also a means to provide polymorphic behavior in that any type's address can be passed into a function that takes a void*. It is up to the implementation to cast the type to the proper type and use it as intended. Quote:
CPP / C++ / C Code:
Output: Code:
MxB |
|
#3
|
|||
|
|||
Re: Argc, Argv[] and Command LineQuote:
CPP / C++ / C Code:
Code:
The drawback of dealing with void* pointers is that the compiler is no longer able to discern syntactic errors as can be done in C++ templates. Neither C or C++ compilers can verify the contents found at an address which has been declared as void*. This is one of the leading motivations Stroustrup had in implementing the concept of C++ templates in the first place -- allow the compiler to perform type-checking on generic code since this could save the development time typically expended when trying to debug why execution went into the weeds just because the specified casting was wrong. |
|
#4
|
||||
|
||||
Re: Argc, Argv[] and Command LineQuote:
Except that Stroustrup didn't "implement the concept of C++ templates" in the first place, 2nd place or otherwise. Alexander Stepanov did and sent it to Stroustrup who embraced it. The "butler" STL code is still available from HP, but is now on a new server (and has been for a few years, at least). None of these points should be taken as a reason to use void* in situations where templates can be used. MxB |
|
#5
|
|||
|
|||
Re: Argc, Argv[] and Command LineHi Guys , But i am going to stop here i have a head ache so OCICAT versus Bob Mexican you guys go at it. One more posting like this and i will go back and start a business program and Hell with programming, well that was my impression, although you guys are saying good and valuable information but you are not realizing how a beginner feel when i encounter things like argc and argv[]., suddenly Howard_L (who i thought he was a teacher before posted this)
Quote:
Special Thanks to Howard_L:" There is the spirit of a teacher in you" and Viva Lunix ( Windows Forget about it) "This copyright of this post Howard_l,and whom he quoted from ..." |
|
#6
|
|||
|
|||
Re: Argc, Argv[] and Command LineQuote:
|
|
#7
|
||||
|
||||
Re: Argc, Argv[] and Command LineQuote:
Uhh, that's not exactly what you wrote. You said "implement the concept of C++ templates," which is, IMO, a somewhat different thing than actually implementing templates using the C++ language and relevant compiler(s). I do not want to get into a semantics "war" with you or anyone else. My primary point was to ensure that Alex received proper credit for bringing the concepts of templates to C++. In the C++ community, introducing a new language feature would obviously solicit the input of its creator, particularly with regard to how to best facilitate the integration of it into the language. However, I strongly support the notion that Stepanov pioneered templates and championed their adoption in C++ with the active support of the C++ community. To me, that is "implemented the concepts," which is probably just a semantic nuance rather than what you meant to say. However, because you didn't mention Stepanov, I thought that it was appropriate to bring it to attention. I think that if you objectively re-read your post, that you will find that it is entirely possible for newbies to mistakenly assume that Stroustrup "invented" C++ templates for lack of a better reference. Perhaps my choice of words and presentation method suggests a confrontational position, which is certainly not intended. It is my only intention to contribute where possible, and I definitely do not know all of the facts involved in the evolution of C++ templates. MxB |
|
#8
|
|||
|
|||
Re: Argc, Argv[] and Command LineWhy don't you guys provide some example so we can follow this french-russian discussion ? ?
|
|
#9
|
||||
|
||||
Re: Argc, Argv[] and Command LineQuote:
Do you speak French or Russian? If not, maybe there is a possibility that you're not going to be able to follow it anyway? The short answer is that you're probably not ready yet for templates. That isn't to suggest in any way whatsoever that you shouldn't review templates or learn about them. It is only that you have more fundamentals to discover before you engage in the "advanced features" of C++. One of the "issues" with advanced features of any programming language is the mindset or, more loosely translated, the "position from which you consider the details of" the various technologies involved in a particular feature. With these "technologies" is often a LOT of concepts that relate to the general problem domain of generic programming and/or reusable code in C++. These issues are often not easily understood even by seasoned programmers who have a good grasp of the fundamentals of the syntax of the language and/or the notions commonly associated with "procedural programming" for a given language syntax. This is incredibly common in C and those who "know C" but fail miserably in C++ without even realizing it. This is the "C++ as a better C" metaphor, but it isn't always truly the case--in terms of programmer experience--because there are appropriate times when using C++ as a better C is, in fact, a true benefit and not merely a representation of an inexperienced programmer "trying" to do what is considered to be "right." Newbies are expected to have no real understanding of many of the advanced concepts of C++. This is akin to suggesting that a 2nd year med student isn't expected to know the details of complex surgical procedures, even if the "scrubs" uniform doesn't differentiate the individual from those with experience. If I put on a pair of scrubs, I could easily be mistaken as a doctor whereas I have absolutely no training at all in the medical profession outside of basic CPR and other, similarly related, life saving techniques. The idea of drilling holes into someone's head would definitely be "scary" for me. Additionally, I wouldn't think that my brain surgeon would be hacking C++ code for the nearby timekeeping device that records staff labor on a particular hospital floor. MxB |
|
#10
|
|||
|
|||
Re: Argc, Argv[] and Command LineQuote:
Yet for an example, consider a linked list as a data structure. The code surrounding the linkage is the same regardless of what data is actually stored at each node. This would be a perfect candidate for being written as a template class (which is a class that is parameterized -- meaning that the types of various internal data can be specified after the class has been written...). Thus, such a class needs to only be written once as a template class as opposed to being rewritten over & over for each specific use within an application. If you are unfamiliar with the STL, this is one of the last features added to C++ in 1994. This is an extensible framework of common data structures which can easily be integrated into most C++ applications. Wikipedia has an entry describing this further: http://en.wikipedia.org/wiki/Standard_Template_Library Given that lists are part of the STL, writing custom code to implement linked lists now isn't required at all. Alternatives to STL include the Boost & STLSoft libraries. The reason alternatives arose is because many compilers in the ~1995 - 2005 era still had issues compiling the STL successfully given that many changes to templates was made in the standard, & it took time for the various compiler vendors to catch up with reliable products. |
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The