Procedures

Hi

How could I create a procedure which gets a changed number of parmeters.

For example we can see the Inc procedure :
It can get one parameter (the variable) or two parameters (the variable and the increased number).

Thanks,
Saar Carmi

Email: saar@bigfoot.com
UIN: 3233305
LVL 4
saar2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

FuzzyLogicCommented:
In C/C++ you can use va_list to do this.
I don't that it is possible in Pascal.
Maybe it is possible in assembly, because the assembler-procedure can get the parameters in the stack.
0
saar2Author Commented:
Do you know that it isn't possiable or you just don't know how to do it?

Thanks anyway,
Saar
0
bslimCommented:
Hmm, I may be wrong at this in Pascal, but I managed to find out that in Java,in order to have a procedure which can utilize  one or two parameters was to make 2 procedures,one with one parameter and one with 2 and naming it both the same.
Hopefully you could do it in Pascal as well.

Hope it works!
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

kellyjjCommented:
It is not possible to have variable length parameter lists to a procedure/function.  You can do it C/C++.
0
saar2Author Commented:
bslim - I don't believe that compailer will let me do it, but I'll check it out.

kellyii - So how is the procedure Inc was built?

Thanks,
Saar
0
bslimCommented:
Another way is to have 2 procedures....hmmm....
but it takes quite a block of mem...

Hope it works again! :)

0
bslimCommented:
kellyjj i think u're rite about that one
I stand corrected...
:)


0
zirconCommented:
Are all of the possible parameters that may be passed to the procedure of the same type (e.g., all integers or all real)?

If they are, could you just use an array to pass varying numbers of "variables" within the array to the procedure?

This solution would be kind of a back door approach, but it should work if all of the parameters passed to the procedure are of the same type or compatble types.

0
saar2Author Commented:
Zircon - I don't realy need to use a procedure like this - I just want to learn how I can build a procedure like Inc for example.

Saar
0
ahoffmannCommented:
saar2, you can't do it in standard pascal. Probably one of its implemetations support it.

Inc (and write, etc.) are pascal built-in functions, and so written (somehow) in assembler.
You may also remember some functions which allow different types of arguments (sqr, abs, etc.).

If you realy want to do this you must either use a precompiler, use a procedure which has max. parameters, or use zircon's array suggestion.
0
FuzzyLogicCommented:
ñ2
You can also send as a parameter only a pointer to a block of data for the procedure. The block may be in any size you want and include any data you want. But then you have much more work to do in the procedure...
0
mitchell042997Commented:
TurboPascal allows Object Oriented Programming, right?  (I haven't tried it out, but I heard.)  In C++ when you build a class you can have two functions with the same name and different parameter lists and the right one will be called.  Try making a class in TP and having two functions in the class with the same name and differing parameter lists.
0
bluebird031198Commented:
I'm PS,
You should create some variable to accept all possible parameters. If the parameter is not passed then assign it to 0(integer) or ''(string)
0
NanosCommented:
Hey saar... as I recal that is IMPOSSIBLE in pascal, it maybe possible in some circumstances in C/C++, but I'm pretty sure that it is not possible in Pascal!!
with regards.. Nanos
0
saar2Author Commented:
Ok everyone - I'll just erase this question.

Thanks anyway
0
zirconCommented:
Have you tested the the possible "work arounds" suggested by ahoffmann, FuzzyLogic, bluebird, myself and others have provided?  You have received some potentially viable answers here, other than "it can't be done."  I don't think it is right to simply delete the question. If truly "can't be done" then that is the correct answer and the points should be awarded to the first person who said it.  If one of the "work arounds" does the trick, then the person who first suggested the best "work around" should be awarded the points.  You should decide who's comment is the best answer or solution and ask them to repost it as an answer or ask for additional follow-up on a particular concept offered as a comment.

Just my 2 cents...
0
wy2lamCommented:
There's no official way to pass variable number of arguments to a Pascal procedure/function.  However, there are a few possible workarounds:

1. Pass a dynamic array which holds the argument
2. A linked list...
3. Just any type of structured data type if you want.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zirconCommented:
e.g., pass an array of records if you want to pass variable number and types of arguments.
0
saar2Author Commented:
wy2lam/zircon/bluebird
Passing an array/record is not a solution because this is not a how INC works.
My problem isn't the programing itself, I just wanted to know how to pass variable number of parameters to a procedure - I don't want to use any trick to do this.

Zircon, I asked "How could I ..." not "Could I ..." - this mean that no answer is not an answer.

Saar

0
saar2Author Commented:
wy2lam, what is a linked list?
how could I do it with it?

Saar
0
zirconCommented:
Saar,

I agree that "it can't be done..." is not a legitimate answer to this question, because of the way you phrased the question and the fact that it can be done.

Passing a data structure such as an array or record is a legitimate answer to the question "How could I..." and does not constitute an answer of "it can't be done..." to the answer "Could I..."

Even if the variable numbers of parameters are not passed in "exactly" the same manner as with the Inc procedure, if the net effect is the ability to pass a variable number of parameters, then the end result is a valid solution. Without the advantages of incorporating the capabilities of assembly languages directly into Pascal code, we may not be able to duplicate the exact method used by the Inc procedure, so a "work-around" is in order.

At any rate, you've gotten some potential solutions that will work.  I think the most comprehensive of them is the current proposed answer from wy2lam.  Perhaps (s)he should get them points.

I hope you find a satisfactory solution.
0
kellyjjCommented:
Saar,  I agree with zircon.  You gotten some pretty good advice here.  YOu should give the points to somebody.
0
wy2lamCommented:
A linked list is a dynamic list (ordered) structure that has a property that an element in it is linked to 1 or 2 other elements in the same list via a pointer / reference.  I dun think it's appropriate to discuss this in this thread since a dynamic array holding pointers to different data types should be enough for this purpose.  (i.e. linked list is inferior to an array for this task).

If you want to know more about linked list, any book about elementary data structure & algorithm should be able to explain this concept clearly.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Pascal

From novice to tech pro — start learning today.