This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Auto calculation of array size

Dear all,

For some reason, I need to declare an array like that

#define STRING2_DESCRIPTOR_LENGTH 16
BYTE code product_string_descriptor[] = {
	STRING2_DESCRIPTOR_LENGTH,
	0x03,
	'U', 0x00,
	'S', 0x00,
	'B', 0x00,
	' ', 0x00,
	'H', 0x00,
	'U', 0x00,
	'B', 0x00
};
When I add characters to the array, I also need to increase STRING_DESCRIPTOR_LENGTH manually.
Do you know some way to calculate the size of the array automatically?
I know in assembly, I can do something like that
product_string_descriptor:
	DB	end - $
	DB	0x03,
	DB	'U', 0x00
	DB	'S', 0x00
	DB	'B', 0x00
	DB	' ', 0x00
	DB	'H', 0x00
	DB	'U', 0x00
	DB	'B', 0x00
end:
How about in C?

Parents
  • "I know in assembly, I can do something like..."

    So why not just do it in assembler, then?!

    If it's difficult in 'C' but easy in Assembler - surely the choice is obvious!!

    There is no problem linking 'C' & assembler in a single Project.

Reply
  • "I know in assembly, I can do something like..."

    So why not just do it in assembler, then?!

    If it's difficult in 'C' but easy in Assembler - surely the choice is obvious!!

    There is no problem linking 'C' & assembler in a single Project.

Children