Compiler Error C10583: Too many elements in initializer
Jorde_V
Posts: 393
Hey Gents,
I haven't programmed AMX in quite a while and I'm currently running into an issue while using a structure and an array following that.
What I get back from the compiler:
I'm not sure what is causing the error, I guess I'm initializing it in the wrong way? I can't find an example in the help files other than initializing it on a per value basis. I'm afraid that's the only way, so I hope you can provide a better way to initialize the values.
I haven't programmed AMX in quite a while and I'm currently running into an issue while using a structure and an array following that.
DEFINE_TYPE STRUCTURE LIGHT_LEVEL_SLIDERS{ integer slider_number; char address[3]; integer value; } DEFINE_VARIABLE light_level_sliders light_level_slider[60]={ {1 ,'000',0},{2 ,'000',0},{3 ,'000',0},{4 ,'000',0}, {5 ,'000',0},{6 ,'000',0},{7 ,'000',0},{8 ,'000',0}, {9 ,'000',0},{10,'000',0},{11,'485',0},{12,'486',0}, {13,'487',0},{14,'488',0},{15,'513',0},{16,'000',0}, {17,'000',0},{18,'000',0},{19,'000',0},{20,'000',0}, {21,'411',0},{22,'427',0},{23,'428',0},{24,'429',0}, {25,'000',0},{26,'000',0},{27,'000',0},{28,'000',0}, {29,'000',0},{30,'000',0},{31,'563',0},{32,'567',0}, {33,'000',0},{34,'000',0},{35,'000',0},{36,'000',0}, {37,'000',0},{38,'000',0},{39,'000',0},{40,'000',0}, {41,'531',0},{42,'530',0},{43,'529',0},{44,'532',0}, {45,'541',0},{46,'913',0},{47,'915',0},{48,'907',0}, {49,'911',0},{50,'827',0},{51,'917',0},{52,'919',0} }
What I get back from the compiler:
---------- Starting NetLinx Compile - Version[2.5.2.420] [05-12-2015 11:48:38] ---------- C:\test.axs WARNING: C:\test.axs(78): C10571: Converting type [string] to [CHAR] ERROR: C:\test.axs(77): C10583: Too many elements in initializer C:\test.axs - 1 error(s), 1 warning(s) NetLinx Compile Complete [05-12-2015 11:48:39]
I'm not sure what is causing the error, I guess I'm initializing it in the wrong way? I can't find an example in the help files other than initializing it on a per value basis. I'm afraid that's the only way, so I hope you can provide a better way to initialize the values.
0
Comments
Hello.
I`d do this another way:
And then maybe some subroutine to init those values:
Don`t know if it`s best way but i guess it`ll do the job.
M.
I'm doing that in the startup code of the virtual device right now, but I was hoping it could be done in a way similar as I'm trying above.
In each source code file, weather that be a axs or axi, I'll initialise any of my globals that instantiate user defined types. The syntax you're trying to use above is AFAIK limited to the 'dev' structure.
That's a shame, really hoped they would've implemented it for this as well.
Just wondering, is there any particular reason to use define_function there? What does it return?
Same here, I do most by trial and error. Mostly because some things don't work the way i expect nor the way the help file implies
The stated reason/thinking is: Use a function when yo want a return from the thing (a result)
Use a Call when you just have a routine to run and don't need a value coming back.
I've asked if there is any performance hit by using a function with no return value vs. using a Call. the engineer wasn't sure. I've never really benchmarked the results myself.
I almost never use Calls as I find them clunky to type. Functions are nice in that I name all mine prefixed with "fn_" as in "fn_MyAwesome_Function()"
I like that they act like keywords in that i just start typing "fn_" and a popup menu of all my functions appears.
I may at some time (if I ever have time) run a benchmark test to see if functions or calls work better process-wise.
Of course you can write a function that doesn't return a value; it just offends my sensibilities. It's a personal preference thing, sort of like "toCamelCase or not to camel case". I don't use autocomplete either, because too often it doesn't Do The Right Thing for me.
And while define_call is certainly an Axcess legacy, that seems irrelevant. The fact that a thing existed before 1999 is not a reason to stop using it. See TV, cars, DEFINE_START...
.
I thought I also read that DEFINE_START shouldn't be used with the NX series anymore. (Same as DEFINE_PROGRAM, but I haven't used that in years anyway)
On a side-note I think it's better to use functions because of the way they work and the syntax is comparable to a lot of other languages, whereas Calls aren't really used. Normally you would use a function and return success or an error code, for simple installations I guess this might seem as overkill. For larger installs however it's a must-have in my opinion. Compiler directives such as #IF_DEFINED are your friends in many cases. (I use this for running test code that I don't want to run in the main program)
DEFINE_START is still required. Take it out, and your project won't compile at all. Technically, all your DEFINE_FUNCTION and DEFINE_MODULE blocks are part of DEFINE _START. You don't want to initialize devices in there anymore, like in the Axcess days, but there are times when you need to populate a structure, or something similar. It's still appropriate for that as well.
is this true??? I have many projects without define_start that compile. they also don't have define_program. They have all the other stuff. granted I'm using NS4.
Like the guys above experienced, there is no need for a DEFINE_START section. I haven't used it, nor have I used a DEFINE_PROGRAM for example. All you need to compile is
You can add functions etc without a DEFINE_START, nothing is required for the compiler.
For example:
This compiles just fine.