Interesting...but would it be 'better' to encapsulate the size of the number string in the struct? De-clutter the library APIs that way. Also maybe a macro for declaring a union of a particular size that sets the sizes of 'complete' and 'number' correctly. On Mon, Jan 30, 2012 at 2:31 PM, Payton Byrd <plbyrd@gmail.com> wrote: > <pipedream> > There is definitely a lot of power in doing this. I wish we had a > text-based numeric library so we can treat string data like numbers as in > COBOL. It could also get us round the lack of partial numbers in cc65. > > Combine that with unions and we could do some cool stuff: > > union value { > char complete[11]; // $ 4000.00 > struct { > char sign; > char number[9]; > } s; > } v1, v2, v3; > strcpy(v1.complete, "$ 99.99"); > strcpy(v2.complete, "$ 0.01"); > strcpy(v3.complete, "$ "); > v3.s.sign = '$'; > v3.s.number = text_add(v1.s.number, v2.s.number, sizeof(v1.s.number) + 1, > sizeof(v2.s.number) + 1); > > This would put "$ 100.00" in v3.complete > Then we could do something like: > i = text_to_uint16(v3.s.number, sizeof(v3.s.number) + 1); > > A **HUGE** benefit of doing this would be the ability to read long lines > of text from a file into a single union variable and parse it and use it > like COBOL does. > </pipedream> > ---------------------------------------------------------------------- To unsubscribe from the list send mail to majordomo@musoftware.de with the string "unsubscribe cc65" in the body(!) of the mail.Received on Tue Feb 7 20:45:39 2012
This archive was generated by hypermail 2.1.8 : 2012-02-07 20:45:42 CET