Why c is strongly typed language




















Learn more. Is C strongly typed? Ask Question. Asked 12 years, 10 months ago. Active 4 years, 2 months ago. Viewed 54k times. Is there a more definitive answer? Improve this question. Sydius Sydius To a C programmer strong typing means pressing the keys harder. C is on the weak side in the typing continuum.

But there are enough items on either side that you can argue either way. While you're at it you might as well ask vi or emacs, netbeans or eclipse, etc. The state of play on Wikipedia was bad enough that I felt compelled to edit several Wikipedia pages. Maybe things are a little better now. Re: Dan's comment to give credit where it's due Peter van der Linden's book "Expert C Programming" contains the following line: "To this day, many C programmers believe that 'strong typing just means pounding extra hard on the keyboard.

Very good question!!! Show 3 more comments. Active Oldest Votes. Terms that do have a well-defined meaning are Dynamically typed means that types are attached to values at run time, and an attempt to mix values of different types may cause a "run-time type error".

Improve this answer. Community Bot 1 1 1 silver badge. Norman Ramsey Norman Ramsey k 57 57 gold badges silver badges bronze badges. Why would you need a "loophole" in a dynamic typing environment? Sydius: From spending much of the last 20 years hanging out with people who design, build, and analyze programming languages and type systems. That's my paid job :- — Norman Ramsey.

Chris: I've never seen a dynamically typed language with 'loophole'. The common use of loophole is to work with a run-time system or OS, e. You could do this in a dynamic setting but I don't know of any attempts. NormanRamsey I think that Chris was referring with his question to: whereas "weakly typed" means "there are loopholes in the type system — Nir Alfasi.

Show 4 more comments. Adam Rosenfield Adam Rosenfield k 94 94 gold badges silver badges bronze badges. Nice answer, although "typecasts A typecast is not like shutting off a warning, it actually changes the interpretation of the value being referenced. You're confusing "static" and "strong" in relation to typing. These two concepts are independent of each other.

Add a comment. C is strongly typed, types are very valid and the compiler will barf if you get them wrong, however, C also provides features for you to bypass this. Compare to languages like BCPL that only have a 'byte' type. Weakly typed doesn't mean a language doesn't have any types, it just means that types can be implicitly coerced from one type to another.

Compare to Python, a strongly typed language in which you must explicitly convert types with function calls. I have this doubt for like forever — Suraj Jain. So: Languages that specify what happens at runtime in every case like adding a number to a string are called dynamically typed. Jules Jules 6, 2 2 gold badges 26 26 silver badges 40 40 bronze badges.

I like your aligning of dynamic and static as forms of strong, vs weak. However, I'm not sure I get your point about statically typed systems stopping divide by zero.

If my statically typed int gets a value from the user or command line arguments or a file, there's nothing the compiler can do to stop that being a zero! There are static type systems that prevent this, but most languages are either weakly or dynamically "typed" with respect to division by zero, because it's undefined behaviour C or they throw an exception Java.

C is more strongly typed than Javascript and less strongly typed than Ada. How's that for definitive? Michael Burr Michael Burr k 49 49 gold badges silver badges bronze badges. C is strongly typed because the type system disallows some type errors. But it's weakly typed in other cases when it's undefined what happens and the type system doesn't protect you.

C is more strongly typed than Javascript and less strongly typed than Ada. Statically typed languages make it easier for IDEs to do this. Static typing makes it easier to work with relational databases and other systems which also rely on static types — It helps you catch type mismatches sooner at compile-time.

It can help reduce the likelihood of some kinds of errors. Asked by: Yissel Bornas asked in category: General Last Updated: 4th May, What does it mean for a language to be strongly typed statically typed what prevents say C from being strongly typed? Strongly typed means that there are restrictions between conversions between types.

Statically typed means that the types are not dynamic - you can not change the type of a variable once it has been created. Is C strongly typed? But with the addition of the dynamic keyword in C 4. These variables are not type-checked at compile time, but only at run-time. Is HTML a dynamic language? Is Perl a dynamic language? Python is a dynamically-typed language. The error is found at compile time. To convince you, we can separate the two steps: compile and run.

For this, we have to wrap the script into an object to produce a standalone Scala code:. Wrapping the script into an object was automatically done by the Scala REPL, which is a tool to evaluate expressions in Scala. Here, we also show how to use type inference in Scala: the types of c and n are inferred to be String and Int respectively.

Being able to detect such mistakes at compile time is extremely powerfull. This is possible with languages that are both strongly and statically typed.

If the language is weakly typed, we fall into one of the pitfalls of Javascript: wrong results at run-time, as we will see with C. This example shows the danger when using weakly typed languages. In fact, when running the compiler, I disabled the warnings with the -w option.

A good compiler with all the warnings activated can detect such things, for instance when compiling without the -w flag:. In more complicated cases for instance using void pointers , the compiler does not catch the errors. We have seen in this blog post two notions of how the computer languages handle the types: the notion of static and dynamic typing, and the notion of strong and weak typing.

Javascript Python Scala C. You can provide the missing context. For example, C is for the most part a statically typed language, because the compiler determines facts about the types of every expression. C is for the most part a type safe language because it prevents values of one static type from being stored in variables of an incompatible type and other similar type errors. And C is for the most part a memory safe language because it prevents accidental access to bad memory.

C is certainly more strongly typed than languages that do not have these restrictions in their type systems. C is not as strongly typed as languages that do enforce these restrictions all the time.

So which is it, strong or weak? It is impossible to say because it depends on the point of view of the speaker, it depends on what they are comparing it to, and it depends on their attitude towards various language features.

Pingback: Seeking clarification on apparent contradictions regarding weakly typed languages Everyday I'm coding. Brilliant explanation, thanks. This put my mind at ease. Pingback: What is late binding? Fabulous adventures in coding. Pingback: How to: Seeking clarification on apparent contradictions regarding weakly typed languages SevenNet.



0コメント

  • 1000 / 1000