the different between function and procedure for C/C++ and Pascal

J

Joona I Palaste

digital said:
hello anyone...

pls explain me , how different between function and procedure for C/C++ and Pascal.

For C and C++:
There is no such thing as "procedure".
For Pascal:
Ask at comp.lang.pascal.
 
D

digital

hello anyone...

pls explain me , how different between function and procedure for C/C++ and Pascal.

Thankx......
 
L

lallous

digital said:
hello anyone...

pls explain me , how different between function and procedure for C/C++ and Pascal.

Thankx......
Hello,

In pascal, the difference between procedure and function is that:
procedure does not have a return value and function have a return value.
So there is no real difference, and all pascal procedures can be written as
functions, and you disregard the return type/value.

In C, all routines, procedures, functions are named a 'function'.

To map from C function to pascal procedure:
procedure myproc(x: integer); { pascal code }
void myproc(int x); /* C code */

The 'void' as a return type is used to denote that function has no return
type.
 
M

Martin Ambuhl

digital said:
hello anyone...

pls explain me , how different between function and procedure for C/C++ and Pascal.

There is no such thing as C/C++, and C has only functions.
Pascal conventionally calls functions that do not return values (that is,
that are executed solely for their side-effects) 'procedures.' In C, they
are just functions with a return type of void.
 
F

Fred Bloggs

digital said:
hello anyone...

pls explain me , how different between function and procedure for C/C++ and Pascal.

The difference is that c++ and pascal are offtopic here, and C doesn't
have procedures.
 
C

Christopher Benson-Manica

lallous said:
The 'void' as a return type is used to denote that function has no return
type.

FMI, is this statement identical to "... function does not return
anything?"
 
A

August Derleth

Christopher said:
FMI, is this statement identical to "... function does not return
anything?"

It's a clumsy and possibly pedantically incorrect way of saying it, but
I think that's what lallous means.

(Perhaps lallous could have said `does not return an object of a usable
type', since trying to inspect or modify an object of void type is not
allowed in C. But that's, again, rather clumsy compared with `does not
return any value.', and could be technically incorrect.)
 
A

August Derleth

Fred said:
The difference is that c++ and pascal are offtopic here, and C doesn't
have procedures.

C++ and Pascal are offtopic, but discussing the differences between them
and C isn't verboten as long as everyone knows that comp.lang.c isn't
guaranteed to know anything about anything other than standard C. (And
even /that/ isn't Guaranteed, but we do try. :) )

Anyway, in Pascal a procedure is a function that does not return a value.

In C, nothing is called a procedure but functions are allowed to not
return anything. This is indicated by giving the function a return type
of void.

C++ is largely similar to C in this respect.
 
P

pete

August said:
It's a clumsy and possibly pedantically incorrect
way of saying it,

I think that's a good way of saying it.
but I think that's what lallous means.

(Perhaps lallous could have said `does not return an object of a
usable type',
since trying to inspect or modify an object of void type is not
allowed in C. But that's, again, rather clumsy compared with `does not
return any value.', and could be technically incorrect.)

I think that's worse.
The return value of a function is an rvalue, not an object.
 
D

Derk Gwen

# hello anyone...
#
# pls explain me , how different between function and procedure for C/C++ and Pascal.

A procedure is void function. A function is nonvoid function.
Instead of assigning to the function name, assign to a local variable with
the same type, say result, and add a return of that at the and

procedure P; begin void P() {
... ...
end }

function F: T; begin T F() {T result;
... ...
F := x; result := X;
... ...
end; return result;}
 
L

lallous

pete said:
Refering to "... function does not return anything"

Hello,

I would be glad to learn how to say it correctly in technical terms.

Or simply, if said again (drawing from previous posts): "It does not
return a usable value" ?
 
P

pete

lallous said:
I would be glad to learn how to say it correctly in technical terms.

Or simply, if said again (drawing from previous posts): "It does not
return a usable value" ?

The first way to say it that pops into my head is
"it doesn't return anything."
"It does not return a usable value", would be a subset
of that statement. Returning a value, is done by writing
the return value to someplace that the calling function
will have access to read.
A function with a void return type, doesn't have to do that.
 
E

E. Robert Tisdale

digital said:
What is the difference between function and procedure for C/C++ and Pascal.

Procedures are only possible in *imperative* computer programming
languages like Fortran, Pascal, C, C++, etc.
The *thread* of execution normally *proceeds* from one imperative
(executable statement) to the next. Flow control "structures"
such as conditionals, loops, switch, case, etc.
may change the normal sequence of execution.
Within the context of each imperative computer programming language,
procedures which return a value are called functions:

language returns value no return value
-----------------------------------------------
C/C++ function void function
Fortran function subroutine
Pascal function procedure

Note that functions need not be procedures:

int min(int i, int j) {
return (i < j)? i: j;
}

and simply return the value of an expression.
It is possible to write useful C programs
without any imperatives at all -- no procedures!
An *applicative* of "functional" programming language
like lisp has no imperatives and, thus, *no* procedures.
 
F

Fred Bloggs

August Derleth said:
C++ and Pascal are offtopic, but discussing the differences between them
and C isn't verboten

comp.lang.c is for the discussion of C as pertains to the relevant standards.
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top