Question

This is the question which my teacher asked in exam. I searched in the book and over net also but i didn't find the answer. I know the first part of the question. Question is regarding Compilers and Assemblers.

Question : What are the advantages of using keyword parameters over positional parameters? Does it incur any overhead during the process of assembling? Does it incur any overhead during execution?

Était-ce utile?

La solution

To answer your questions:

  1. What are the advantages?

    The main advantage is to avoid problems where you define the wrong parameter in the wrong place. So for example:

    strlen(s);
    

    has just one parameter, so no risk to get it wrong. However:

    strpos(s, "needle", 34);
    

    may be wrong because, for example, s and "needle" may be inverted. With named parameters:

    strpos(start_pos => 34, string => s, needle => "needle");
    

    you can be sure that the parameters will be properly placed once compiled in assembly (because for the final result in assembly, it is obviously very important!)

  2. Overhead during assembling process?

    Yes. Obviously you need to read that extra data and your compiler has to re-order the parameters. Also it means the headers MUST declare the parameters with names. In C, you often see things like this:

    strpos(const char *, const char *, int);
    

    Now you have names in declarations and when functions are being used. That's many more identifiers to parse and possibly memory to allocate, etc.

    Would that overhead be visible to our naked eye on modern computers? Probably not.

  3. Does the final binary run slower?

    No. Either way the result is exactly the same in the final binary. Only one way is a lot safer than the other. (i.e. if we all were forced to always specify the parameter name, then many bugs would be avoided... however, scripts such as PHP or python would be slower to run since you need to re-parse those parameters each time you execute the script.)

Autres conseils

The parameters that are assigned while calling the macro are called Keyword parameters e.g

%macro test()
---
--
%mend test;
%test(l=sassuer d=admit); //Keyword parameters

While one that are hardcoded are called Positional parameters; e.g

%macro test (l=sasuser , d=admit) // Positional parameters
   ----
%mend test;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top