bugTiny C Compiler - Bugs: bug #13213, Cannot use integer for array size

 
 

bug #13213: Cannot use integer for array size

Submitter:  None
Submitted:  Fri 27 May 2005 10:27:15 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 13 Sep 2005 12:18:18 PM UTC, comment #1: 

Index: tinycc/tcc.c
===================================================================
RCS file: /cvsroot/tinycc/tinycc/tcc.c,v
retrieving revision 1.179
diff -r1.179 tcc.c
126c126
< #define TOK_MAX_SIZE        4 /* token max size in int unit when stored in str
ing */
---

> #define TOK_MAX_SIZE        31 /* token max size in int unit when stored in st

ring */
326a327,328

> static int *user_macro_ptr;
> static int user_saved_buffer[TOK_MAX_SIZE + 1];

4430a4433,4461

> /* varray */
> static inline void put_user_tok_start()
> {
>     user_macro_ptr = user_saved_buffer;
> }
>
> static inline void put_user_tok_end()
> {
>     const int user_tok_size = (uint32_t)user_macro_ptr - (uint32_t)user_saved_

buffer;

>     *user_macro_ptr = 0;
>     unget_buffer_enabled = 1;
>     if (macro_ptr) {
>         memmove((uint8_t*)macro_ptr+user_tok_size, macro_ptr, user_tok_size-1)

;

>         memcpy(macro_ptr, user_saved_buffer, user_tok_size-1);
>     } else {
>         macro_ptr = user_saved_buffer;
>     }
> }
>
> static inline void put_user_tok(int last_tok)
> {
>     int i, n;
>
>     *user_macro_ptr++ = last_tok;
>     n = tok_ext_size(tok) - 1;
>     for(i=0;i<n;i++)
>         *user_macro_ptr++ = tokc.tab[i];
> }
> /* ~varray */

6842a6874,6875

> /* varray */
> static int expr_check_const(void);

6915,6917c6948,6976
<             n = expr_const();
<             if (n < 0)
<                 error("invalid array size");
---

>             /* varray */
>             if (expr_check_const()) {
>                 n = vtop->c.i;
>                 vpop();
>                 if (n < 0)
>                     error("invalid array size");
>             } else {
>                 put_user_tok_start();
>                 put_user_tok('=');
>                 put_user_tok(TOK_alloca);
>                 put_user_tok('(');
>                 while(tok != ']') {
>                     put_user_tok(tok);
>                     next();
>                 }
>                 put_user_tok(')');
>                 skip(']');
>                 if (tok != ';')
>                     error("not support varray type");
>                 put_user_tok(tok);
>                 put_user_tok_end();
>                 next();
>
>                 s = sym_push(SYM_FIELD, type, 0, -1);
>                 type->t = (VT_PTR | VT_CONSTANT);
>                 type->ref = s;
>
>                 return;
>             }

7871a7931,7943

>
> /* varray */
> static int expr_check_const(void)
> {
>     int last_tok = tok;
>     expr_const1();
>     if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) != VT_CONST) {
>         unget_tok(last_tok);
>         return(FALSE);
>     }
>     return(TRUE);
> }
> /* ~varray */


Anonymous
Fri 27 May 2005 10:27:15 PM UTC, original submission:  

The following code will not compile with tcc 0.9.22. It exits saying "main.c:4: constant expression expected".


int main(int argc, char * argv[])
{
int array_size = 10;
char array[array_size];

return 0;
}

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by grischka (Updated the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-10-18 grischka StatusNone Fixed
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code