473,890 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is C type checking?

Hi,

I am reading the book "Concepts of programming languages" by R. W.
Sebesta. He said:

"One of the most important reasons why C is both liked and disliked is
its lack of complete type checking. For example, functions can be
written for which parameters are not type checked. Those who like C
appreciate the flexibility; those who do not like it find it too insecure."

Could you explain this to me with more detail? The book doesn't give any
more explanation. Thank you very much. I greatly apprecite it.

Nov 15 '05 #1
20 2106

"Xiaoshen Li" <xl**@gmu.edu > wrote in message
news:dk******** ***@osf1.gmu.ed u...
Hi,

I am reading the book "Concepts of programming languages" by R. W.
Sebesta. He said:

"One of the most important reasons why C is both liked and disliked is its
lack of complete type checking. For example, functions can be written for
which parameters are not type checked. Those who like C appreciate the
flexibility; those who do not like it find it too insecure."

Could you explain this to me with more detail? The book doesn't give any
more explanation. Thank you very much. I greatly apprecite it.


He might be referring to variadic functions like printf?

e.g. int printf(const char *, ...);

the ... means anything might be passed, and it's up the you not to lie to
printf.

Nov 15 '05 #2
Xiaoshen Li <xl**@gmu.edu > wrote:
"One of the most important reasons why C is both liked and disliked is
its lack of complete type checking. For example, functions can be
written for which parameters are not type checked. Those who like C
appreciate the flexibility; those who do not like it find it too insecure."


The author is presumably speaking about variadic functions such as
printf(), which are passed arguments whose types cannot be enforced at
compile time. The first argument to printf, for example, is a string
that tells the function the number and types to expect of the
remaining arguments at run time.

char foo[]="foo=%s";
printf( foo, 42 ); /* Causes UB at run time, but the compiler cannot
know this in general. */

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Nov 15 '05 #3
In article <dk***********@ osf1.gmu.edu>, Xiaoshen Li <xl**@gmu.edu > wrote:
"One of the most important reasons why C is both liked and disliked is
its lack of complete type checking. For example, functions can be
written for which parameters are not type checked.
Traditional (pre-ANSI) C did not provide any way to specify the types
of function parameters. ANSI C in 1989 added "prototypes ", which
specify the parameter types. If you use these - and some compilers
have a flag that insists on them - then you get type checking for
parameters (though not for the variable parameters of functions like
printf).

If you want to deliberately defeat type-checking, you can use explicit
casts. And pointers can be converted to and from void * without a
cast (so you can pass a pointer of any type to a function expecting a
void *, thus providing a certain amount of genericity). This is a
reasonable compromise.
Those who like C appreciate the flexibility; those who do not like it
find it too insecure."


I don't think it's common to write functions without prototypes in
order to avoid type checking. It makes much more sense to uses
prototypes and explicit casts where necessary (which is hardly ever).

-- Richard
Nov 15 '05 #4
ri*****@cogsci. ed.ac.uk (Richard Tobin) writes:
If you want to deliberately defeat type-checking, you can use explicit
casts. And pointers can be converted to and from void * without a
cast (so you can pass a pointer of any type to a function expecting a
void *, thus providing a certain amount of genericity). This is a
reasonable compromise.


(I'm sure you realize this, but the OP might not.) Casts[*] can
be used to defeat type checking, but many don't do anything of
the sort. For example, a cast to `unsigned char' is often used
to bring a character into the proper range for passing to
isupper() or another <ctype.h> function.
[*] "Explicit casts" is redundant. All casts are explicit.
--
int main(void){char p[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Nov 15 '05 #5
In article <87************ @benpfaff.org>,
Ben Pfaff <bl*@cs.stanfor d.edu> wrote:
[*] "Explicit casts" is redundant. All casts are explicit.


All casts in C are explicit.

But I was describing what you can do in C, in the context of
programming languages in general. If I said "C uses null-terminated
strings", would you say that was redundant because all C strings are
null-terminated?

-- Richard
Nov 15 '05 #6
In article <dk***********@ pc-news.cogsci.ed. ac.uk>,
Richard Tobin <ri*****@cogsci .ed.ac.uk> wrote:
In article <87************ @benpfaff.org>,
Ben Pfaff <bl*@cs.stanfor d.edu> wrote:
[*] "Explicit casts" is redundant. All casts are explicit.
All casts in C are explicit.

But I was describing what you can do in C, in the context of
programming languages in general.


In that case, the term you'd want is "explicit conversions". A cast is
a source code construct that forces a conversion and is, by definition,
explicit.
dave

--
Dave Vandervies dj******@csclub .uwaterloo.ca What should such a standard mandate for systems which don't use
directories, such as OS390? --Richard Heathfield and

A well-engineered fake. Chris Dollin in comp.lang.c
Nov 15 '05 #7
In article <dk**********@r umours.uwaterlo o.ca>,
Dave Vandervies <dj******@csclu b.uwaterloo.ca> wrote:
In that case, the term you'd want is "explicit conversions". A cast is
a source code construct that forces a conversion and is, by definition,
explicit.


Where do you get this definition from?

-- Richard
Nov 15 '05 #8
ri*****@cogsci. ed.ac.uk (Richard Tobin) writes:
In article <dk**********@r umours.uwaterlo o.ca>,
Dave Vandervies <dj******@csclu b.uwaterloo.ca> wrote:
In that case, the term you'd want is "explicit conversions". A cast is
a source code construct that forces a conversion and is, by definition,
explicit.


Where do you get this definition from?


C99 6.5.4.

That section does use the phrase "explicit cast", but there's no
implication that a cast can be implicit.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #9
Michael Mair wrote:
Richard Tobin wrote:
In article <dk**********@r umours.uwaterlo o.ca>,
Dave Vandervies <dj******@csclu b.uwaterloo.ca> wrote:
In that case, the term you'd want is "explicit conversions". A cast is
a source code construct that forces a conversion and is, by definition,
explicit.

Where do you get this definition from?

The standard:
C89, 3.2; even though 3.3.4 talks of _explicit_ casts
C99, 6.3; 6.5.4 does no more mention explicit casts

^^^^^^^ wrong. Just did not see it on the
screen.
Cheers
Michael

--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 15 '05 #10

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

Similar topics

15
2335
by: Terje Slettebř | last post by:
Hi. I'm new here, and sorry if this has been discussed before; I didn't find it searching the PHP groups. (I've also read recommendations to cross-post to the other PHP groups, but if that is discouraged, please let me know. At the same time, please then let me know which of the many PHP groups to post to. :) ) In PHP5, you can provide "type hints" for functions, like this:
23
2861
by: sashan | last post by:
I'm a Python newbie. I have been using c++ for 5 years and before that I was programming in Pascal. The one thing that annoys me about python is dynamic typing because I find myself making typographical errors of the sort that would under C++ be picked up by the compiler at compiler time. With Python I have to wait for the error to appear at runtime in order for me to correct it. I find this inefficient. Any advice about how to get around...
12
2077
by: Aaron Watters | last post by:
I'm doing a heart/lung bypass procedure on a largish Python program at the moment and it prompted the thought that the methodology I'm using would be absolutely impossible with a more "type safe" environment like C++, C#, java, ML etcetera. Basically I'm ripping apart the organs and sewing them back together, testing all the while and the majority of the program at the moment makes no sense in a type safe world... Nevertheless, since...
3
2362
by: George Sakkis | last post by:
Explicit type checking is not typically seen in Python code, and usually that's not a big problem; most typing errors are likely to raise a TypeError or AttributeError sooner than later. There are cases, though, where typing errors are not caught (at least not early) because different classes happen to have methods with the same name; that's really subtle with the special methods like __eq__, __hash__, etc. that are common to all (or at...
5
3017
by: Tongu? Yumruk | last post by:
I have a little proposal about type checking in python. I'll be glad if you read and comment on it. Sorry for my bad english (I'm not a native English speaker) A Little Stricter Typing in Python - A Proposal As we all know, one of the best things about python and other scripting languages is dynamic typing (yes I know it has advantages and disadvantages but I will not discuss them now). Dynamic typing allows us to change types of...
6
14325
by: Web Developer | last post by:
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
3
2123
by: Vinodh Kumar P | last post by:
Whenever I read any C++ literature I find the words "C++ is statically type checked".OK.Agreed. Is there any language that supports "Dynamic type checking"? In such a case any type can be assigned to any other type during compile time?
8
3340
by: Ashish | last post by:
Hi all, I have interface declared like public IBaseInterface { } then a generic collection like
669
26408
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
0
9978
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9819
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10811
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10919
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
8015
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7169
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6041
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4674
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3275
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.