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. 20 2053
"Xiaoshen Li" <xl**@gmu.edu> wrote in message
news:dk***********@osf1.gmu.edu... 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.
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)cyberspace.org | don't, I need to know. Flames welcome.
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 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[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
In article <87************@benpfaff.org>,
Ben Pfaff <bl*@cs.stanford.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
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.stanford.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
In article <dk**********@rumours.uwaterloo.ca>,
Dave Vandervies <dj******@csclub.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 ri*****@cogsci.ed.ac.uk (Richard Tobin) writes: In article <dk**********@rumours.uwaterloo.ca>, Dave Vandervies <dj******@csclub.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_Keith) 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.
Richard Tobin wrote: In article <dk**********@rumours.uwaterloo.ca>, Dave Vandervies <dj******@csclub.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
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Michael Mair wrote: Richard Tobin wrote:
In article <dk**********@rumours.uwaterloo.ca>, Dave Vandervies <dj******@csclub.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.
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.org> 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.
We're going round in circles here. I know that *in C*, casts are
always explicit. But I was explaining something to someone who was
evidently not familiar with the details of C, so it would be unhelpful
to rely on that fact. As a term in computer science, casts may be
implicit, so referring to "explicit casts" when describing the
features available in C is not redundant.
-- Richard
According the responses I got from you guys, Sebesta is exaggerating too
much here, based on his strong expression in the textbook. His bookd is
great. I feel hard to believe that he is wrong.
(Actually this book is edited by him. Each chapter is writen by
different authors.)
Xiaoshen Li wrote: 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.
Xiaoshen Li wrote: According the responses I got from you guys, Sebesta is exaggerating too much here, based on his strong expression in the textbook. His bookd is great. I feel hard to believe that he is wrong.
(Actually this book is edited by him. Each chapter is writen by different authors.)
Xiaoshen Li wrote: 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.
Wouldn't a *complete* lack of type checking
mean that you *couldn't* write functions for
which parameters *are* checked?
--
pete
pete wrote:
<snip> Xiaoshen Li wrote:
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.
Wouldn't a *complete* lack of type checking mean that you *couldn't* write functions for which parameters *are* checked?
Hmm, yeah. That's why it doesn't say that.
Or are you trying to make a subtler point here? :-)
S. ri*****@cogsci.ed.ac.uk (Richard Tobin) writes: In article <ln************@nuthaus.mib.org>, Keith Thompson <ks***@mib.org> 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.
We're going round in circles here. I know that *in C*, casts are always explicit. But I was explaining something to someone who was evidently not familiar with the details of C, so it would be unhelpful to rely on that fact. As a term in computer science, casts may be implicit, so referring to "explicit casts" when describing the features available in C is not redundant.
I don't recall seeing the term "cast" used other than in reference to
the explicit conversion construct in C (and in closely related
languages like C++). If I weren't talking about C, I would always use
the term "conversion" rather than "cast".
Then again, C must have gotten the term from somewhere.
--
Keith Thompson (The_Other_Keith) 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.
Skarmander wrote: pete wrote: <snip> Wouldn't a *complete* lack of type checking mean that you *couldn't* write functions for which parameters *are* checked? Hmm, yeah. That's why it doesn't say that.
Or are you trying to make a subtler point here? :-)
No, I just read it wrong.
--
pete
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.org> wrote: I don't recall seeing the term "cast" used other than in reference to the explicit conversion construct in C (and in closely related languages like C++).
I think it may first have been used in Algol68, where it refers to an
explicit conversion. On the other hand, SQL seems to use the term
"implicit cast" frequently.
And of course (as Google will demonstrate) the term "implicit cast" is
frequently used in the context of C, regardless of the standard. So I
think even in that context, "explicit cast" is redundant only when
talking to very specialised audiences.
-- Richard
Richard Tobin wrote: In article <ln************@nuthaus.mib.org>, Keith Thompson <ks***@mib.org> wrote:
I don't recall seeing the term "cast" used other than in reference to the explicit conversion construct in C (and in closely related languages like C++).
I think it may first have been used in Algol68, where it refers to an explicit conversion. On the other hand, SQL seems to use the term "implicit cast" frequently.
And of course (as Google will demonstrate) the term "implicit cast" is frequently used in the context of C, regardless of the standard.
.... and "teh" is an alternate spelling for "the"
Results 1 - 10 of about 8,210,000 for teh. (0.06 seconds)
Teh enb.
--
pete
Xiaoshen Li wrote: 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.
Didn't any one take Pascal?
C allow do operations on mixed types PASCAL does not it is strongly typed.
in C you can add an int to a char. In PASCAL the types must match.
in C you can cast to set the wrong type of variable to a function. In PASCAL
not gonna work.
Neil Kurzman wrote: C allow do operations on mixed types PASCAL does not it is strongly typed.
in C you can add an int to a char. In PASCAL the types must match.
That depends on how you look at it.
The usual arithmetic conversions make arithmetic operands
of the addition operator, the same type,
and at least as high ranking as int.
--
pete This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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"...
|
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...
|
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...
|
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?
...
|
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...
|
by: Ashish |
last post by:
Hi all,
I have interface declared like
public IBaseInterface
{
}
then a generic collection like
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |