Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6598127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:18:00+00:00 2026-05-25T18:18:00+00:00

I use gcc version 4.3.2 (Debian 4.3.2-1.1). I wrote a simple program in C

  • 0

I use gcc version 4.3.2 (Debian 4.3.2-1.1).
I wrote a simple program in C to implement and test a integer stack. Stack is implemented by the STACK structure. I used a constant named STACKSIZE to define the STACK’s size.
My program code looks like this:

#include<stdio.h>
#include<stdlib.h>

#define STACKSIZE 10;

typedef struct {
    int size;
    int items[STACKSIZE];
} STACK;

void push(STACK *ps, int x)
{
    if (ps->size == STACKSIZE) {
        fputs("Error: stack overflow\n", stderr);
        abort();
    } else
        ps->items[ps->size++] = x;
}

int pop(STACK *ps)
{
    if (ps->size == 0){
        fputs("Error: stack underflow\n", stderr);
        abort();
    } else
    return ps->items[--ps->size];
}

int main() {
    STACK st;
    st.size = 0;
    int i;
    for(i=0; i < STACKSIZE + 1; i++) {
        push(&st, i);
    }
    while(st.size != 0)
        printf("%d\n", pop(&st));
    printf("%d\n", pop(&st));
    return 0;
}

when i used
#define STACKSIZE 10;
gcc would return following errors:

ex_stack1.c:8: error: expected ‘]’ before ‘;’ token
ex_stack1.c:9: warning: no semicolon at end of struct or union
ex_stack1.c: In function ‘push’:
ex_stack1.c:13: error: expected ‘)’ before ‘;’ token
ex_stack1.c:17: error: ‘STACK’ has no member named ‘items’
ex_stack1.c: In function ‘pop’:
ex_stack1.c:26: error: ‘STACK’ has no member named ‘items’
ex_stack1.c: In function ‘main’:
ex_stack1.c:33: error: expected ‘)’ before ‘;’ token

when i used

const int STACKSIZE=10;

gcc would return following error:

ex_stack1.c:8: error: variably modified ‘items’ at file scope

when i used

enum {STACKSIZE=10};

gcc would compile my program successfully.

What happenned? How should i modify my program to use

#define STACKSIZE 10;

or

const int STACKSIZE=10;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:18:00+00:00Added an answer on May 25, 2026 at 6:18 pm

    Drop the semicolon, it’s wrong

    #define STACKSIZE 10;
                        ^
    

    If you keep it the preprocessor will translate int items[STACKSIZE]; into the obviously wrong int items[10;];.

    For the const bit, there is a C FAQ.

    The value of a const-qualified object is not a constant expression in
    the full sense of the term
    , and cannot be used for array dimensions,
    case labels, and the like.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if it is safe to use the latest GCC version, or
With gcc versions before 3.3 and with the MS compiler I use the following
How hard would it be to use GCC instead of VC++ from within Visual
What windows C IDE can I use that will use gcc to compile and
Can I configure the VS.NET 2008 IDE to use gcc as a compiler?
For some reason, I should use gcc to compile a C file, then link
I have a c-library which I use in gcc. The library has the extension
Can I force the gcc to use a null canary or terminator canary, when
I'm trying to build GCC for use with an AVR microcontroller and avr-ada, and
I use GNUStep to compile Objective-C on Windows 7 using GCC and MinGW. I'd

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.