Table of Contents
C++ functions exchange information by means of parameters and arguments. The term parameter refers to any declaration within the parentheses following the function name in a function declaration or definition; the term argument refers to any expression within the parentheses of a function call.
The following rules apply to parameters and arguments of C++ functions:
Except for functions with variable-length argument lists, the number of arguments in a function call must be the same as the number of parameters in the function definition. This number can be zero.
- The maximum number of arguments (and corresponding parameters) is 253 for a single function.
- Arguments are separated by commas. However, the comma is not an operator in this context, and the arguments can be evaluated by the compiler in any order. There is, however, a sequence point before the actual call.
- Arguments are passed by value; that is, when a function is called, the parameter receives a copy of the argument's value, not its address. This rule applies to all scalar values, structures, and unions passed as arguments.
move
contructor can help reduce the duplication if the argument value is used only once. - Modifying a parameter does not modify the corresponding argument passed by the function call. However, because arguments can be addresses or pointers, a function can use addresses to modify the values of variables defined in the calling function.
- In the old style, parameters that are not explicitly declared are assigned a default type of int .
- The scope of function parameters is the function itself. Therefore, parameters of the same name in different functions are unrelated.
This project focus on regrouping the set of a arguments(over 253 parameters can be processed) of a function in a nutshell, let's say all
, then assign each argument its value respectively as all.arg1=..; all.arg2=..; all.arg3=..; ...all.argn=..;
within the function body/scope.
.
├── CMakeLists.txt
├── include
│ └── FctArgs.h
├── README.md
└── src
└── Demo.cpp
This is a sample code of how you may regroup a function arguments in a class. To get a local copy up and running follow these simple steps.
This is an example of how to list things you need to use the software and how to install them.
- cmake
sudo apt-get install cmake
- Clone the repo
git clone https://github.com/zoumson/FunctionArgumentsTemplate.git
- Go to the project directory source
cd FunctionArgumentsTemplate
- Create empty directories
build
, andbin
mkdir build && mkdir bin
- Generate the exectutable
demo
and move it tobin
cd build && cmake .. && make && cd ..
- run
./bin/demo
- Output
Demo FctArgs template class
void function2Args(arg_2_is)
First arguemnt: 100
Second arguemnt: test 2 args
void function3Args(arg_3_isb)
First arguemnt: 5
Second arguemnt: test 3 args
Third arguemnt: 1
- Back to the initial file structure configuration
rm -r bin build
All the headers files are well docummented, read through the comments
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Adama Zouma - - [email protected]
Project Link: https://github.com/zoumson/FunctionArgumentsTemplate