## Generate One MEX Function That Supports Multiple Signatures

An entry-point function is a top-level MATLAB® function from which you generate code. If your entry-point function has inputs, you must specify the properties of the inputs to generate a MEX function. In this case, the generated MEX function works only with the signature of the entry-point function that you specify during code generation.

If your entry-point function supports multiple signatures, you can generate a single MEX function instead of generating a separate MEX function for each signature. The generated MEX function works with the multiple signatures provided during code generation.

By using multisignature MEX functionality, you can:

• Generate one MEX function that supports the multiple signatures that you specify in the entry-point function.

• Reduce the overhead involved in generating and using separate MEX functions for each signature of your entry-point function.

• Achieve MATLAB function-like behavior in the generated MEX function.

### Generating Multisignature MEX Function

To generate a multisignature MEX function, consider this function `myAdd`:

```function y = myAdd(a,b) %#codegen y = a+b; end ```
Suppose that you want to generate a MEX function from `myAdd` that works with three different data types: `double`, `int8`, and `vector of doubles`. Specify the three arguments as: `{1,2}`, `{int8(2), int8(3)}`, and ```{1:10, 1:10}```.

To generate code for `myAdd` function, at the MATLAB command line, run this `codegen` command:

`codegen -config:mex myAdd.m -args {1,2} -args {int8(2),int8(3)} -args {1:10,1:10} -report`
This syntax generates a single MEX function `myAdd_mex` for the signatures specified in the `codegen` command.

At the command line, call the generated MEX function `myAdd_mex`. Make sure that the values you pass to `myAdd_mex` match the input properties that you specified in the `codegen` command.

`myAdd_mex(3,4)`
```ans = 7```
`myAdd_mex(int8(5),int8(6))`
```ans = int8 11```
`myAdd_mex(1:10,2:11)`
```ans = 3 5 7 9 11 13 15 17 19 21```

Running the MATLAB function `myAdd` with these input values produces the same output. These test cases verify that `myAdd` and `myAdd_mex` have the same behavior.

## Limitations

Multisignature MEX generation does not support:
{"ft_lang_label":"__label__en","ft_lang_prob":0.5761306,"math_prob":0.9406185,"size":2218,"snap":"2020-45-2020-50","text_gpt3_token_len":554,"char_repetition_ratio":0.19467027,"word_repetition_ratio":0.0,"special_character_ratio":0.23128945,"punctuation_ratio":0.13701923,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.96235806,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-12-03T20:23:46Z\",\"WARC-Record-ID\":\"<urn:uuid:ab601998-945f-4312-b5c4-0dc923798a53>\",\"Content-Length\":\"67599\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:aa9312d6-1fe5-42e1-89ed-2b56e123eec3>\",\"WARC-Concurrent-To\":\"<urn:uuid:a4744a7b-c01d-48af-9727-0a7956586dc6>\",\"WARC-IP-Address\":\"23.56.12.57\",\"WARC-Target-URI\":\"https://fr.mathworks.com/help/coder/ug/mex-generation-for-multiple-signatures.html\",\"WARC-Payload-Digest\":\"sha1:SDLZFY4QQKCY7A2XYL2J3DBCAZ23TKFP\",\"WARC-Block-Digest\":\"sha1:E6XVIG34ZWV3QTVIPNYK3C35YCFXOBYX\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-50/CC-MAIN-2020-50_segments_1606141732696.67_warc_CC-MAIN-20201203190021-20201203220021-00676.warc.gz\"}"}