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 7497355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:03:56+00:00 2026-05-29T19:03:56+00:00

I am writing a compiler for a c-like language. Currently, the compiler supports arrays

  • 0

I am writing a compiler for a "c-like" language. Currently, the compiler supports arrays in local scope. Each element of an array may be accessed using bracket notation—a[0], a[1],.... to support this data structure, a symbol table is used to keep track of the symbols in the current scope, and the address of the next available memory space. to demonstrate, consider the following code:

int a[5]; int b;

using a stack implementation, and given a 4 byte aligned memory: in order to access, e.g. element a[1], I calculate the memory location by

element = ((index+1) * 4) + a.Address; // a.Address is the address of a, which is stored in the symbol table, and index is 1 in this case.

so, the symbol table doesn’t store the address of each individual element of ‘a’, only the address of the symbol and, for each symbol, the next memory address.

I am assuming that the c language uses a stack based implementation for arrays in local scope, such as what I’ve done. However, how does the C language pass a local array as a parameter to a function, like the following?

foo(int[] a) {}

Would a C compiler use the heap or the stack to pass the foregoing array?

  • 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-29T19:03:59+00:00Added an answer on May 29, 2026 at 7:03 pm

    In C, arrays decay to pointers when passed as function arguments; foo(int a[]) is identical to foo(int * a), and only the pointer to the first element “survives” into the function call. There is no way to recover the array size from the pointer within the function call.

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

Sidebar

Related Questions

I'm writing a compiler for a simple C-like language for a course I'm taking.
I'm writing a compiler for a small language, and my Parser class is currently
I'm currently writing a compiler for a small language that compiles to JavaScript. In
I'm writing a compiler which uses C as an intermediate code which is (Currently)
I am writing a compiler in Python using Eclipse with PyDev. I've come to
I am experimenting with writing a toy compiler in ocaml. Currently, I am trying
I am currently writing a programming language in C/C++ as an exercise (but mostly
I'm working on writing a compiler for a language running on .net and one
I am writing a LLVM code generator for the language Timber, the current compiler
I am writing a compiler for a small imperative language. The target language is

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.