1

Have a look at the Verilog code below:

module first(input a, input b, output c)
assign c= a&b;
endmodule

And then we call this module into another module like as below

module second(input d, input e, output f)

first instance_name (.a(d), .b(e), .c(f));

endmodule

As we can clearly see that which port is connected with which port. While calling a function in C++, its always a danger that we will miss a port and place some unwanted variable there.

Is there any similar way of doing things in C++?

John McnZ
  • 107
  • 5
  • Please add the following information - a) A clearer description of what the verilog code does, and b) how you would write a function call in C++ and how that is insufficient to achieve what you want to do. – cigien May 26 '23 at 07:50
  • @cigien Its now clearly showing what it is doing. – John McnZ May 26 '23 at 07:52
  • 2
    You can't use named arguments in C++. But since the C++20 standard structure/class members can be named when initializing objects. – Some programmer dude May 26 '23 at 07:53
  • And if you don't provide all required arguments, or use the wrong type (and implicit conversion is not possible), the C++ compiler *will* complain. – Some programmer dude May 26 '23 at 07:55
  • 2
    See [here](https://pdimov.github.io/blog/2020/09/07/named-parameters-in-c20/) for what @Someprogrammerdude refers to – though to cover output parameters as well you'll have to include references in the struct – that has quite a smell if you don't provide a constructor for as well, but then again losing the possibility to use designated initialisers... – Aconcagua May 26 '23 at 08:08
  • Actually for me, the bigger issue is to connect right variables with right ones. But thanks for tips by our respected posters. – John McnZ May 26 '23 at 11:14

2 Answers2

3

While C++ does not support named argument idiom out of box, it can be done with help of designated initializers:

struct t_Input
{
    t_Input(void) = delete;
    t_Input(int) {}
};

struct t_Args
{
    t_Input a;
    t_Input b;
    t_Input c;
};

void First(t_Args args);

void Second()
{
    //First({.a{1}, .c{3}}); // error
    First({.a{1}, .b{2}, .c{3}});
}

online compiler

Also modern IDEs, such as Visual Studio, offer handy inline hints feature: enter image description here

user7860670
  • 35,849
  • 4
  • 58
  • 84
1

You are referring to naming the arguments in a C++ function when calling it. No, this is not possible.

A good IDE will nevertheless label your arguments for you.

infinitezero
  • 1,610
  • 3
  • 14
  • 29
  • any good ide suggestion? – John McnZ May 26 '23 at 08:04
  • 1
    @JohnMcnZ Just Clion for C++.. (a highly configured emacs is even better in my opinion. You then have to install a proper LSP-Server) – Eldinur the Kolibri May 26 '23 at 08:05
  • @JohnMcnZ I personally have been running with [eclipse](https://www.eclipse.org/downloads/packages/release/2023-03/r/eclipse-ide-cc-developers) for years now. Some might argue about the choice, but there's simply nothing else that fits my personal needs better... And in contrast to Clion its open-source, thus free. About function arguments: Eclipse shows the complete signature on hovering the mouse over the function name. – Aconcagua May 26 '23 at 08:16