- for(remain=0; remain<DCL_ELEM(type); remain++)
- pic16_emitDB(SPEC_CVAL(val->etype).v_char[ remain ], ptype, p);
-
- if ((remain = (DCL_ELEM (type) - strlen (SPEC_CVAL (val->etype).v_char) - 1)) > 0) {
- while (remain--) {
- pic16_emitDB(0x00, ptype, p);
- }
+ /* if the value is a character string */
+ if(IS_ARRAY (val->type) && IS_CHAR (val->etype)) {
+ /* length of initializer string (might contain \0, so do not use strlen) */
+ ilen = DCL_ELEM(val->type);
+
+ if(!DCL_ELEM (type))
+ DCL_ELEM (type) = ilen;
+
+ /* len is 0 if declartion equals initializer,
+ * >0 if declaration greater than initializer
+ * <0 if declaration less than initializer
+ * Strategy: if >0 emit 0x00 for the rest of the length,
+ * if <0 then emit only the length of declaration elements
+ * and warn user
+ */
+ len = DCL_ELEM (type) - ilen;
+
+// fprintf(stderr, "%s:%d ilen = %i len = %i DCL_ELEM(type) = %i SPEC_CVAL-len = %i\n", __FILE__, __LINE__,
+// ilen, len, DCL_ELEM(type), strlen(SPEC_CVAL(val->etype).v_char));
+
+ if(len >= 0) {
+ /* emit initializer */
+ for(remain=0; remain<ilen; remain++)
+ pic16_emitDB(SPEC_CVAL(val->etype).v_char[ remain ], ptype, p);
+
+ /* fill array with 0x00 */
+ while(len--) {
+ pic16_emitDB(0x00, ptype, p);