![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
Weak typing (roughly) means that the compiler or interpreter of the language allows a variable to be treated as if it was a different type, or converted to that type. Strong typing means that the compiler or interpreter doesn't allow implicit conversions between types.
Weak typing is often viewed as more "programmer friendly", as a program is more likely to compile i.e. you can get something running quickly. Strong typing tends to require the programmer to take account of the type of a variable whenever it is used (eg it forces multiple functions to be written to do one thing, if those functions act on different types). Hence strong typing tends to be advocated by people who need to explicitly code everything (and know that no unintended effects will occur, due to quiet conversions). Both C and C++ are weakly typed by a litteral interpretation of those definitions, as they both allow variables to be implicitly converted to different types. If you view "typing" as a continuum from "weak" to "strong", then C++ is more stongly typed than C. There are other languages that are more weakly typed than C (scripting languages are typically in this category). There are also other languages (eg Ada) that are more strongly typed than C++. |
|
|
|
|
|
#12 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
Incidentally, int main() and int main(void) are the same thing in both C and C++.
The difference is that, in C++, calling main() [and it's supported variants] is forbidden. For example, main() cannot call itself recursively. In C, such calls are allowed (although, in practice, they are often considered to be bad style). IIRC, a side effect of this is that, in C++, computing the address of main() [i.e. as a pointer to function] is also forbidden. |
|
|
|
|
|
#13 | |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 599
Rep Power: 4
![]() |
Quote:
#include <stdio.h>
int main();
void foo()
{
main(1);
}Now change it to this, and the compiler will produce error that main() was declared without parameters. #include <stdio.h>
int main(void);
void foo()
{
main(1); <<< error here
}Finally, make the same test programs in *.cpp program. The compiler will reject both programs. |
|
|
|
|
|
|
#14 | |
|
Programming Guru
![]() ![]() ![]() |
<TANGENT>
Quote:
82.5% ![]() Being that its maybe, implies a yes or no... since I answered yes, I was half right on the third question, which should supply a weight of half the possible points. At least I passed ![]() </TANGENT>
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
|
#15 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4
![]() |
1. int main() in C ONLY
means that main returns an integer and that main may have zero, one, two, three... arguments. This is confusing for a beginner. In practice it means you cannot ask the code inside main to use any arguments. 2. Any form of void main()... void main(int argc, char *argv[]) is a problem waiting to happen. Even if your compiler allows it. All C code invokes something called startup. startup calls main. When main ends startup examines what it thinks main should have returned. It returns that value to the caller. What I've just described is part of the C standard (startup can variously be called _startup and other things like that). The important part is the return. If main does not return anything, then startup returns what it finds after main exits. In this case what startup finds it will be garbage. Most callers implicitly expect a return a value. If the return is -134455664 (garbage) instead of zero or maybe one, you can be in a world of hurt. |
|
|
|
|
|
#16 |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 599
Rep Power: 4
![]() |
main() does not have to return an int. It can return anything you want it to return. However, then control returns to the startup code as previously described by Jim, the program will treat whatever is returned as an int.
char* main()
{
static char buf[80];
return buf;
}There are a lot of other incompatibilities between C and C++. Anyone interested can read some of them here Last edited by Ancient Dragon; Jul 8th, 2005 at 2:01 PM. |
|
|
|
|
|
#17 | ||||
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
Quote:
int main(); When you define main() i.e. you do this int main()
{
/* the body of main */
}Quote:
There is no clause in the C or C++ standards that prevents a compiler from supporting other means of entering a program, such as void main() or [under windows] WinMain(). Quote:
Quote:
The standard says nothing about how the return value from main() should be used, except that returning zero usually indicates "success". It is the operating system (or command line interpreter) which interprets that value. Compilers that support void main() usually ensure some sensible value is given back to the operating system. But the standard is silent on what value should be given in this case, as it says nothing about void main(). |
||||
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|