Is C a block structured language?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AmberJain
    Recognized Expert Contributor
    • Jan 2008
    • 922

    Is C a block structured language?

    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-->
    Originally posted by Herbert schildt in C++-Complete reference
    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----->
    Originally posted by BOOK
    "C is block structured language"

    My C faculty said--->
    Originally posted by my C faculty
    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
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    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.

    Comment

    Working...