Three stupid C questions: ++,...

B

BartC

jean francois said:
I see . . . so in effect, if() is really a special kind of fonction ?

No. It's just a coincidence that it looks like function syntax. C just likes
lots of brackets and parentheses around things.

C:

if (expression) statement; [else statement;]

Pascal:

if conditional-expression then statement; [else statement;]

Block statements in C:

{statement; ...;}

Pascal:

begin statement; ... end

(with slightly different rules about semicolons as you will no doubt come
across.)

But if you're translating C to Pascal, as I think you said somewhere, then
you don't have to write this stuff, just figure out what it does, which is
easier.)

You need to worry more about C features that might not translate so simply;
dynamic arrays for example. (Last time I used Pascal, arrays were a fixed
size.)
 
E

Eric Sosman

[...]
I see . . . so in effect, if() is really a special kind of fonction ?

No. C uses paired parentheses in several distinct ways:

- To group sub-expressions in a larger expression, for example
`(a + b) * (c + d)'.

- As part of the `if', `while', `do...while', `for', and
`switch' statements.

- As part of a cast operator, as in `(double)m / n'.

- As part of the `sizeof' operator when applied to a type name:
`sizeof(int)'.

- As part of a function call, like `sin(x)' or `abort()'.

- As part of the definition of a "function-like" macro, and as
part of its invocation.

- ... and probably in a few more ways that I have overlooked.

C "overloads" many punctuation characters this way. Curly braces
`{}' surround statement blocks, but also surround initializer lists
and are part of the syntax of struct and union declarations. The
equal sign `=' is often the assignment operator, but may also be
part of the required syntax of an initialization. The `&' may mean
"address-of" or "bit-wise AND", `-' may mean be the subtraction
operator or the unary negation operator, and the list goes on.

So: The fact that `if(x)' resembles `sqrt(x)' does not mean
both are functions, nor that both are statements. It only means
that C uses `()' pairs in more than one way.
 
G

Guest

On Tue, 12 Jun 2012 13:52:46 -0400, Eric Sosman wrote:


I see . . . so in effect, if() is really a special kind of fonction ?

no more than 'if' is a function in Pascal
 
G

Guest

On 06/12/2012 08:16 AM, (e-mail address removed) wrote:

Even if the question is "Is this correct?" :)

fair point. But I wasn't even sure which language he was posting in! Perhaps his questions should have been "what is the correct syntax for a pointer to a struct?" or whatever he as trying to ask. Perhaps his question should really have been "what is the best way to learn the basics of C?".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top