Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Is C a block structured language?

Question posted by: ambrnewlearner (Expert) on July 23rd, 2008 05:28 PM
HELLO,

First of all, I accept that this is a too simple question but I got different opinions in different books and so I'm posting it here......

The question is simple.....Is C a block structured language?

But the answers by different authors differ like a pendulum (some say YES while others say NO to this question)

For example.........

Herbert schildt in "C++-Complete reference" says-->
Quote:
In your previous programming experience, you may have heard the term block-
structured applied to a computer language. Although the term block-structured
language does not strictly apply to C, C is commonly referred to simply as a
structured language. It has many similarities to other structured languages, such
as ALGOL, Pascal, and Modula-2.
The reason that C (and C++) is not, technically, a block-structured language is that
block-structured languages permit procedures or functions to be declared inside
other procedures or functions. Since C does not allow the creation of functions
within functions, it cannot formally be called block-structured.



Another book said simply----->
Quote:
"C is block structured language"



My C faculty said--->
Quote:
C is not block structured languges





In many other books and tutorials, I found similar answers.
So please tell me whether C is a block structured language?

THANKS in advance.........
weaknessforcats's Avatar
weaknessforcats
Moderator
4,766 Posts
July 23rd, 2008
11:14 PM
#2

Re: Is C a block structured language?
OK. Here goes.

C is a blocked structured language.

C++ is to replace C.

Therefore, C++ is also a blocked structured language.

Now C++ does have some OO features (which you don't have to use) but even if you do, the program is still block structured. It's just that you don't need to code all of the block calls yourself like you would have to do in C.

An object-oreinted language ahs to support the Liskow Substitution Principle. This principle says a derived object can be substituted for a base object and thereafter when treated as a base object behaves like the derived object that it really is.

You cannot do this in C++. The most you can do is substitute the address of a derived objec as the address of a base object but you cannot substitute the object itself. In this sense C++ is not object-oriented.

However, the address substitution is usually enough to accomplish the same end as substituting th actual object so in that sense you can say that C++ can be object-oriented.

Please note that that a C++ program has calls made by the compiler to accomplish the object-oriented magic. Were you to have a C program, you could make those calls yourself and have an object-oriented program in C.

Note that block structured does not always mean defining procedures within procedures but also means using procedures wirthin procedures. Neither C nor C++ permits defining a procedure within a procedure but you can certainly use procedures within procedures.

Reply
Reply
Not the answer you were looking for? Post your question . . .
189,919 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top C / C++ Forum Contributors