472,975 Members | 1,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,975 software developers and data experts.

C++: "Type Checking"

Hi,

I come across the term "type checking" very often in my readings on C++, and
have never heard it in Java. Besides the simplistic answer that it checks
the "type", what more does it mean?
WD

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.504 / Virus Database: 302 - Release Date: 24/07/2003
Jul 19 '05 #1
6 14235

"Web Developer" <no****@hotmail.com> wrote in message
news:3f********@news.iprimus.com.au...
Hi,

I come across the term "type checking" very often in my readings on C++, and have never heard it in Java. Besides the simplistic answer that it checks
the "type", what more does it mean?
WD


I think its a question of timing. All languages check types, you aren't
allowed to multiply two strings in any language (AFAIK). But some languages
delay type checking until the program runs. C++ does most of its type
checking at compile type. This results in faster code, smaller data and
quicker detection of type errors, but it also means a more complex language.

We say C++ is a strongly typed language. In general I would say strong
typing is a good thing but there are occasions where you want to relax it
and check types at run time. That's where virtual functions and RTTI come
in.

john
Jul 19 '05 #2
On Mon, 11 Aug 2003 05:20:48 -0400, "ghl" <gl*******@comcast.net> wrote:
"John Harrison" <jo*************@hotmail.com> wrote in message
news:bh************@ID-196037.news.uni-berlin.de...

"Web Developer" <no****@hotmail.com> wrote in message
news:3f********@news.iprimus.com.au...
> Hi,
>
> I come across the term "type checking" very often in my readings on C++,

and
> have never heard it in Java. Besides the simplistic answer that itchecks > the "type", what more does it mean?
>
>
> WD
>


I think its a question of timing. All languages check types, you aren't
allowed to multiply two strings in any language (AFAIK). But some

languages
delay type checking until the program runs. C++ does most of its type
checking at compile type. This results in faster code, smaller data and
quicker detection of type errors, but it also means a more complex

language.

We say C++ is a strongly typed language. In general I would say strong
typing is a good thing but there are occasions where you want to relax it
and check types at run time. That's where virtual functions and RTTI come
in.


Java is also a strongly typed language and checks for compatible types for
method arguments and return values at compile time.


Nope. Consider classes A, B and C in separate files, where A uses B uses
C, and A is the "main" program. Compile all. Change C to be incompatible
with B. Compile class A using Sun's compiler: no errors reported. Run.
Runtime error.

That could not happen in C++.

C++ has _global_ static type checking; Java has runtime type checking.

Jul 19 '05 #3
On Mon, 11 Aug 2003 13:34:20 GMT, to********@hotmail.com (tom_usenet) wrote:
On Mon, 11 Aug 2003 10:23:27 GMT, al***@start.no (Alf P. Steinbach)
wrote:
Nope. Consider classes A, B and C in separate files, where A uses B uses
C, and A is the "main" program. Compile all. Change C to be incompatible
with B. Compile class A using Sun's compiler: no errors reported. Run.
Runtime error.

That could not happen in C++.

C++ has _global_ static type checking; Java has runtime type checking.
The Java language has stronger static type checking than C++. e.g.
implicit conversions from double to int, etc. don't exist. C++ however
has better idioms for static type checking, thanks to using generics
rather than an Object base-of-all class. Java encourages use of the
evil instanceof operator.

I think you're talking about the link time safety that C++ has thanks
to name mangling. But C++ will just crash if you replace a DLL with
another one with incompatible types, so I don't get your point.


DLLs are not part of C++.

Java will detect the problem if you recompile
Nope. Java will only detect the problem if you recompile class B.
You have an executable system without recompiling class B (and this is
not theoretical, it has been a major problem in some large Java projects).

just as happens with C++.


Nope. With C++ you have global type-checking. You cannot obtain an
executable with static type inconsistencies.

Jul 19 '05 #4
ghl
"Alf P. Steinbach" <al***@start.no> wrote in message
news:3f****************@News.CIS.DFN.DE...
On Mon, 11 Aug 2003 05:20:48 -0400, "ghl" <gl*******@comcast.net> wrote:
"John Harrison" <jo*************@hotmail.com> wrote in message
news:bh************@ID-196037.news.uni-berlin.de...

"Web Developer" <no****@hotmail.com> wrote in message
news:3f********@news.iprimus.com.au...
> Hi,
>
> I come across the term "type checking" very often in my readings on C++, and
> have never heard it in Java. Besides the simplistic answer that it

checks
> the "type", what more does it mean?
>
>
> WD
>

I think its a question of timing. All languages check types, you aren't
allowed to multiply two strings in any language (AFAIK). But some

languages
delay type checking until the program runs. C++ does most of its type
checking at compile type. This results in faster code, smaller data and
quicker detection of type errors, but it also means a more complex

language.

We say C++ is a strongly typed language. In general I would say strong
typing is a good thing but there are occasions where you want to relax it and check types at run time. That's where virtual functions and RTTI come in.


Java is also a strongly typed language and checks for compatible types formethod arguments and return values at compile time.


Nope. Consider classes A, B and C in separate files, where A uses B uses
C, and A is the "main" program. Compile all. Change C to be incompatible
with B. Compile class A using Sun's compiler: no errors reported. Run.
Runtime error.


Wrong. Been there. Tried that.
Created classes as above, all returning String type reference variable.
Changed return type of C to int. Message on recompiling A gives:
..\C.java:3: incompatible types
found : java.lang.String
required: int
public int info = "I'm c";
^
..\C.java:13: incompatible types
found : int
required: java.lang.String
return info;
^
2 errors
--
Gary
Jul 19 '05 #5
ghl
"Alf P. Steinbach" <al***@start.no> wrote in message
news:3f****************@News.CIS.DFN.DE...
On Mon, 11 Aug 2003 13:06:42 -0400, "ghl" <gl*******@comcast.net> wrote:
"Alf P. Steinbach" <al***@start.no> wrote in message
news:3f****************@News.CIS.DFN.DE...
<<large snip>> "Change" means: change the source code of class C, compile class C.

Then compile class A, or not (it makes no difference), and run:
Exception in thread "main" java.lang.NoSuchMethodError: C.result()Ljava/lang/String; at B.result(B.java:5)
at A.main(A.java:5)
Got it?


Ah, I get what you're driving at. Yes, you get that. Does the same thing
happen in C++ with the linker detecting the change?
The Java error at runtime is detected because there is no linker and the
type checking can only occur when class C is actually loaded and checked.
I get your point.
--
Gary
Jul 19 '05 #6
On Mon, 11 Aug 2003 13:36:19 -0400, "ghl" <gl*******@comcast.net> wrote:
"Alf P. Steinbach" <al***@start.no> wrote in message
news:3f****************@News.CIS.DFN.DE...
On Mon, 11 Aug 2003 13:06:42 -0400, "ghl" <gl*******@comcast.net> wrote:
>"Alf P. Steinbach" <al***@start.no> wrote in message
>news:3f****************@News.CIS.DFN.DE...

<<large snip>>
"Change" means: change the source code of class C, compile class C.

Then compile class A, or not (it makes no difference), and run:
Exception in thread "main" java.lang.NoSuchMethodError:

C.result()Ljava/lang/String;
at B.result(B.java:5)
at A.main(A.java:5)
Got it?


Ah, I get what you're driving at. Yes, you get that. Does the same thing
happen in C++ with the linker detecting the change?


In practice the linker detects the change, yes.

In theory there need not be a linker in a C++ implementation, but the
_language_ (standard) guarantees global static type-checking whatever
execution system is actually used.

There's no runtime error because you don't get an executable.

Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dmgauntt2002 | last post by:
I have some javascript ASP code that sets the expiry date on a cookie to five years from now. The code worked until today, when I got the following error message: Microsoft JScript runtime...
2
by: Andrew Proctor | last post by:
Hello This is not a big problem, but I was hoping someone a bit more knowlegable than I could explain something to me. I have a simple function behind a form which writes changed values to a...
5
by: Dave | last post by:
How do I check in a Windows Forms app if any controls have changed? I have a form that collects data, and I want to prompt the user if they try to exit the app, or load a new file, without saving...
3
by: Jon | last post by:
I'm learning about datatables. When using the example provided by MS in the ..NET Framework Class Library for DATATABLE (see below) I get an error on line 3 that says "Type expected". Is something...
14
by: Geoff Jones | last post by:
Hi I'm trying to use a class that I've written in a form. Unfortunately, when I write something like: Public x As New myClass I get the compile time error: "Type Expected". Indeed, the...
0
by: Phill. W | last post by:
In a ListView Control, you can type in a short prefix and the ListView scrolls to the next Item matching that prefix. Is there anyway to make processing this work with a Subitem? I can sort...
4
by: Nie longhai | last post by:
I have a generic method in a class as follow: T Get<T>(string key) { ..... return Convert.ChangeType(v, typeof(T)) } when I use it in my code:
5
by: Diwa | last post by:
Does the "value" type (value as in key-value pair )of "std::map" require a default ctor even if it is not used ? If I comment out Line 1 in the code attached later, i.e remove the default ctor...
5
by: Davros9 | last post by:
Trying to get Regular Expressions working....... ---------------- Public Function SepString(InField As String) As String ''seperates on space and comma Dim RE As New RegExp Dim Matches As...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.