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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:42:15+00:00 2026-05-13T10:42:15+00:00

It’s known that big local/global variables may cause to a stack overflow. I know

  • 0
  1. It’s known that big local/global variables may cause to a stack overflow.
    I know that using pointers and allocating space in memory helps to overcome this problem.
    But is it the only option? What happens if I have (or need) too-many pointers in global scope?

  2. Regarding the stack space: Is a global struct-type variable takes space in the stack, or acts like a pointer? Do I need to create a pointer of a struct variable type in order to reduce the stack load?

  3. Does the following code allocates memory also to the char** variable named BIG?

    // in the header file  
    typedef struct myStruct {  
        BIG[256][256];  
        int baz;  
    } myStruct;
    
    // in the c file  
    myStruct* foo;  
    foo = (myStruct*) malloc( sizeof(*foo) ); 
    
  4. How can I easily cast the return value of malloc()? In question #3 I wrote:

    foo = (myStruct*) malloc( sizeof(*foo) );

    But I prefer to write something like:

    foo = (foo) malloc( sizeof(*foo) ); // the compiler reports an error

    Which will ease the pain when editing the code (when changing the type of foo).

English isn’t my native language so sorry for any lack of clarity.

  • 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-13T10:42:16+00:00Added an answer on May 13, 2026 at 10:42 am

    Neil already answered your questions, here are my comments on your 3rd and 4th questions.

    Does the following code allocates memory also to the char** variable named BIG?

    typdef struct myStruct {
        char BIG[256][256];
        int baz;
    } myStruct;
    
    myStruct* foo;
    
    foo = (myStruct*) malloc( sizeof(*foo) );
    

    (I fixed the error in BIG‘s type.) This will allocate space for BIG, although BIG is not of type char **. BIG is of type “array [256] of array [256] of char“. In value contexts, it is equivalent to “pointer to array [256] of char“.


    How can I easily cast the return value of malloc()? In question #3 I wrote:

    foo = (myStruct*) malloc( sizeof(*foo) );
    

    But I prefer to write something like:

    foo = (foo) malloc( sizeof(*foo) ); // the compiler reports an error
    

    You’re almost correct in what you want to do, but the right way requires even less typing! The most idiomatic, easy to read, and “type-change safe” way is:

    #include <stdlib.h>
    foo = malloc(sizeof *foo);
    

    Or more generally,

    #include <stdlib.h>
    T *foo = malloc(size * sizeof *foo);
    

    No casts are needed, since malloc() returns void *, which can be converted to any pointer type back and forth without any loss of information. Note that this form does not use the type of foo in the malloc() call, so it is type-agnostic. Also, sizeof operator doesn’t need parentheses if it’s used on an object (but they’re needed if it’s used on a type).

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

Sidebar

Ask A Question

Stats

  • Questions 290k
  • Answers 290k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Perfect place for recursion: ... TraverseFolder(rootFolderID, userContext) { var folderById… May 13, 2026 at 5:50 pm
  • Editorial Team
    Editorial Team added an answer You basically have two options: eiter abstract all file-system related… May 13, 2026 at 5:50 pm
  • Editorial Team
    Editorial Team added an answer Have you already checked out the manual page on fgetcsv?… May 13, 2026 at 5:50 pm

Related Questions

Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I want use html5's new tag to play a wav file (currently only supported
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.