문제

I see the term 'construct' come up very often in programming readings. The current book I am reading, "Programming in C" by Stephen Koching has used it a few times throughout the book. One example is in the chapter on looping, which says:

"When developing programs, it sometimes becomes desirable to have the test made at the end of the loop rather than at the beginning. Naturally, the C language provides a special language construct to handle such a situation. This looping statement is known as the do statement."

In this case what does the term 'construct' mean, and does the word 'construct' have any relation to an object 'constructor' in other languages?

도움이 되었습니까?

해결책

In this case you can replace the word construct with syntax.

does the word 'construct' have an relation to an object 'constructor' in other languages?

No. These two terms are different. There is nothing like constructor in C

다른 팁

It's a generic term that normally refers to some particular syntax included in the language to perform some task (like a loop with the condition at the end). It has no relation at all with constructors.1


  1. Well, besides the fact that constructors are a particular language construct in many OO languages.

does the word 'construct' have an relation to an object 'constructor' in other languages?

The sentence uses the noun, not a verb, meaning of the word "construct":

construct (n) - something (such as an idea or a theory) that is formed in people's minds.

In this case, "construct" refers to an abstract way of describing something (namely, a loop) in terms of the syntax of that particular language. "Language construct" means "a way to do [something] with that language".

A construct is simply a concept implementation mechanism used by a given programming language - the language's syntax.

In your case, the concept here is a loop and its construct is the manner in which it is implemented by the C programming language.

Programming languages provide constructs for various programming concepts that define how these programming concepts are implemented in that language.

Does the word 'construct' have an relation to an object 'constructor' in other languages?

The two terms are different, a constructor is used in Object Oriented Languages such as java, it is not available in the C programming language.

first of all, remember that c-language, not an Object Oriented Programming language. the constructor is an OOP terminology. So there is Construct refers to syntax and pre-defined keywords like do and while in this case.

The word “construct” as used in computer programming has very broad or general meaning. I hope these thoughts will help to explain what is meant by the word “construct” in programming.

A computer program is a list of instructions that the computer is able to (a) understand and (b) execute (perform or carry out). The simplest program would be a list of - let’s call them statements - that the computer would execute in sequence, one after the other, from the first to the last, and then end. But that would be incredibly limiting - so limiting in fact that I don’t think computers would ever have become much more than simple calculators. One of the fundamental differences between a simple calculator and a computer is that the statements do not have to be executed in sequence. The sequence can be interrupted by “special” instructions (statements) which can divert the flow of execution from one stream to a totally different stream which has a completely different agenda.

The first obvious way this is done is with methods (functions or procedures). When a method is called, the flow of execution is diverted from one stream of statements to a totally different stream of statements, often unrelated to the stream from which it came. If that concept is accepted, then I think that an instruction that calls a method could also be regarded as a “construct”.

Let’s divert this discussion for a moment to talk about “blocks” of code. Programmers who work in languages like C, C++ or Java know that pairs of opening and closing braces (curly brackets), are used to identify blocks of code. And it’s blocks of code that divide a program up into different processes or procedures. A block of code that is headed by say a while() loop is just as valid as a method, in that it interrupts the otherwise unimpeded flow of execution through a program. The same applies to the many categories of operators. “new” will divert the flow of statement execution to a constructor method. So we have all these various syntactical expressions that have one thing in common - they divert the flow of execution which, left to its own devices - would happily proceed executing statements of code in sequence one after the other, without any interruption.

So I am suggesting that the word “construct” is a useful collective noun that embraces all of these different and diverse syntactical expressions e.g. if() for() switch() etc. that use the different categories of operators to perform functions that are defined in their respective blocks of code. Would love to hear other opinions.

In short, all in-built features(like an array, loop, if else statements) of the programming language are language constructs.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top