View previous topic :: View next topic |
Author |
Message |
Blackjackmaster
Joined: 14 May 2023 Posts: 30
|
Data Definitions |
Posted: Thu Aug 03, 2023 1:56 pm |
|
|
Hello,
Is there a limit on how many variables can be used in a data definition?
example:
void writeRegisterI2C(int8 deviceAddress, int8 address, int8 val); |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9168 Location: Greensville,Ontario
|
|
Posted: Thu Aug 03, 2023 7:34 pm |
|
|
Probably more than you can keep track of...(my gut says 255 )
Really, passing a lot of variables in a single function will be a nightmare. I suspect once you get to 10 or 12 it get 'challenging' to remember what they're supposed to do.I can say I've ever seen any code use more than 8 or 9.
I'd like to know how many you need to pass. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19358
|
|
Posted: Fri Aug 04, 2023 3:28 am |
|
|
C historically had a limit of 127.
ANSI C90 only requires 31 is the minimum supported. So code that
is intended to be portable should not use more than this.
Generically though a function that has a huge number of variables, should
probably be split into a number of smaller functions, just on efficiency
grounds.
There is also a line length limit in the compiler, and unless the variables
use very small names, this will probably be hit first.
Remember also, a structure is a single variable, and could contain hundreds
of sub components. Much easier to pass a singe entity like this than
have loads of separate items. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9168 Location: Greensville,Ontario
|
|
Posted: Fri Aug 04, 2023 7:48 am |
|
|
hmm... magical 'binary' numbers...!!!!
255..127, 31 |
|
![](templates/subSilver/images/spacer.gif) |
Blackjackmaster
Joined: 14 May 2023 Posts: 30
|
Data Definitions |
Posted: Fri Aug 04, 2023 9:03 am |
|
|
Thanks for the information.
I was looking in the manual for what the line length is and was unable to find this number. I will be passing 6 variables with one function. I will keep the name as short as possible. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19358
|
|
Posted: Fri Aug 04, 2023 11:43 am |
|
|
6 wouldn't be a problem even with long names. |
|
![](templates/subSilver/images/spacer.gif) |
|