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

  • Home
  • SEARCH
  • 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 5960203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:47:37+00:00 2026-05-22T18:47:37+00:00

I have a function with the signature: int exe(int stack[][STACKSIZE], int sp[], int reg[][REGISTERSIZE],

  • 0

I have a function with the signature:

int exe(int stack[][STACKSIZE], int sp[], int reg[][REGISTERSIZE], int next_instruct[],
        int next_inst[], int cur_proc, int *terminate);

It has the final two lines of:

printf("TWO cur_proc: %d\n",cur_proc);
return NORMAL;

And is called like this:

printf("ONE cur_proc: %d\n",cur_proc);
msg = exe(stack,sp,reg, next_instruct, next_instruct, cur_proc, &terminate);
printf("THREE cur_proc: %d\n",cur_proc);

And I am passing in cur_proc which is considered a “read-only” (not that it should matter being passed by value) variable inside of exe(). Do my stuff inside of exe().

And my output is:

ONE cur_proc: 1
TWO cur_proc: 1
THREE cur_proc: -1

This is very confusing to me as I can’t see any reason that this could possible be overwritten with a negative one.

What is a possible reason for this strange behavior?

  • 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-22T18:47:38+00:00Added an answer on May 22, 2026 at 6:47 pm

    You probably are writing outside the bounds of one of the arrays.

    Inside the function, you are looking at a copy of the variable in the calling function, not at the original variable. Therefore, the printf() inside the function does not tell you about when the value got corrupted in the calling function.

    Look to the arrays that are passed, and the one that is modified inside the function is the most likely culprit – or the ones that are modified. Since none of the arrays are const-qualified, it is hard to say which are modified, but something is likely treading out of bounds.

    If you want to track when the change to cur_proc in the calling function occurs from inside the called function, pass a pointer to cur_proc into the function – as well as or instead of the value – and print the value via the pointer.

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

Sidebar

Related Questions

I have this function signature I have to match typedef int (*lua_CFunction) (lua_State *L);//target
I have a C function with the following signature: int my_function(int n, struct player
I have a unmanaged C++ function with the following signature: int function(char* param, int
I have a 3rd party function with signature: int secretfoo(int numargs, ...); I can
In AS3 you have a function on a string with this signature: function replace(pattern:*,
I have a function with the same name, but with different signature in a
Let's say we have a method signature like public static function explodeDn($dn, array &$keys
I have a function that takes, amongst others, a parameter declared as int privateCount
I have the following function signuture: public JsonResult PopulateGrid(int page, Guid? accountId, Guid? systemUserId,
I have a function that takes an int-pointer and exposed it via boost::python. How

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.