-4
#define xyz

static xyz  myObject *__my_getitem (myObject* a, myObject *b) {
     myObject *r;
     .........
     ........
     return r;
 }
  1. What is static?
  2. What is xyz doing with static
  3. Why is there a * in front of __my_getitem
  4. What is the difference betweern myObject* a and myObject *a (position of *)
GSerg
  • 76,472
  • 17
  • 159
  • 346

2 Answers2

2

What is static?

Function definitions that are prefaced by "static" have their scope limited. They can only be seen and used by functions in the same source file. You would do that when you have a function that has no value outside of the processing taking place in the current file, or you want to limit usage so that it can be modified in the future with less ramifications due to its limited scope.

What is xyz doing with static

In this specific case, xyz gets replaced with nothing, so it does nothing. In the general case, it would likely be modifying how the compiler generates this function, changing the "calling convention". That is, xyz would have some meaning to the compiler and is not part of the C language.

Why is there an asterisk in front of __my_getitem

It shows that the __my_getitem function returns a pointer to a myObject.

What is the difference between myObject* a and myObject *a (position of *)

Nothing, as the syntax is flexible.

Scooter
  • 6,802
  • 8
  • 41
  • 64
2

What is static?

It means different things in different contexts; you'll need to read your book to understand all of its meanings. In this case, it means that the function is only available inside this source file, and not in any that are compiled separately and then linked to it.

What is xyz doing with static?

Causing confusion. It's an empty macro (defined in the first line) so, before compiling the program, the preprocessor will replace it with nothing.

Why is there a * in front of __my_getitem

* after a type changes the type to a pointer; so this means that the function returns a pointer to a myObject. (By the way, you should never declare a name with two consecutive _ characters; names like that are reserved.)

What is the difference betweern myObject* a and myObject *a (position of *)

Nothing at all; whitespace never changes the meaning of the program, except where it is needed to separate tokens. Some people fight holy wars over the semantic implications of those two styles, but the language doesn't care.

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644