HACKER Q&A
📣 mucholove

Is there a C like language with keywords for parameters?


Looking for something very simple.

I just want C. But instead of having to remember the names of every parameter—I would like to call them such as:

      send(fileDescriptor: 1, bytes: ptr, length: 20, flags:0);
Swift does do this—but it is terribly slow to compile. A C transpiler would be fine :)


  👤 zzo38computer Accepted Answer ✓
It might be possible perhaps to use a macro that passes a structure and extracts the elements (at least if the compiler supports GNU extensions); I don't know if the compiler will be able to optimize that in all cases, though.

Example:

  static int xyzzy_(int x,int y) {
    printf("x=%d\ny=%d\n",x,y);
    return x*y;
  }
  
  typedef struct {
    int x,y;
  } xyzzy_parameters;
  
  #define xyzzy(...) ({ const xyzzy_parameters macro_args={__VA_ARGS__}; xyzzy_(macro_args.x,macro_args.y); })
  
  int main(int argc,char**argv) {
    printf("[%d]\n",xyzzy(.x=6,.y=7));
    return 0;
  }