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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:53:35+00:00 2026-06-11T08:53:35+00:00

I’m porting some C Code to C#. I’m stuck at a piece where I

  • 0

I’m porting some C Code to C#. I’m stuck at a piece where I don’t quite understand the Author’s intention of writing code in unfamiliar fashion.

The Code is:

typedef struct{
  Int32 window[2][8];     
  Int32 windowF[2][8];
  short Index; 
}BLOCK_SWITCHING_CONTROL;

maxWindow = SrchMaxWithIndex( &blockSwitchingControl->window[0][8-1],
                                      &blockSwitchingControl->Index, 8);

*****************************************************************************
*
* function name: SrchMaxWithIndex
* description:  search for the biggest value in an array
* returns:      the max value
*
**********************************************************************************/
static Int32 SrchMaxWithIndex(const Int32 in[], Int16 *index, Int16 n)
{
  Int32 max;
  Int32 i, idx;

  /* Search maximum value in array and return index and value */
  max = 0;                                                       
  idx = 0;                                                       

  for (i = 0; i < n; i++) {

    if (in[i+1]  > max) {
      max = in[i+1];                                             
      idx = i;                                                   
    }
  }
  *index = idx;                                                  

  return(max);
}

As you can see, when SrchMaxWithIndex is being called, not an array but a single Int32 is being passed as its first parameter which is of course wrong. But because I know for sure the C code has nothing wrong with it, I’m convinced that I’m missing something here.
What am I missing? What was the Author’s intention to pass a single Int32 instead of an array?

So far I’ve ported the above to C# in the following manner:

static class BLOCK_SWITCHING_CONTROL{
  Int32[][] window = new int[2]{new int[8], new int[8]};     
  Int32[][] windowF = new int[2]{new int[8], new int[8]};
  short Index; 
};


 maxWindow = SrchMaxWithIndex( blockSwitchingControl.window[0]/*[8-1]*/,
                                      out blockSwitchingControl.Index);

*****************************************************************************
*
* function name: SrchMaxWithIndex
* description:  search for the biggest value in an array
* returns:      the max value
*
**********************************************************************************/
static Int32 SrchMaxWithIndex(Int32 _in[], out Int16 index)
{
  Int32 max;
  Int32 i, idx;

  /* Search maximum value in array and return index and value */
  max = 0;                                                       
  idx = 0;                                                       

  for (i = 0; i < _in.Length; i++) {

    if (in[i+1]  > max) {
      max = in[i+1];                                             
      idx = i;                                                   
    }
  }
  index = idx;                                                  

  return(max);
}

But it is just to remove the errors in C#.

  • 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-06-11T08:53:36+00:00Added an answer on June 11, 2026 at 8:53 am

    OK, first, I have to assume you have a mistake in the code:

    blockSwitchingControl->windowN
    

    Does not exist in the BLOCK_SWITCHING_CONTROL structure. So I’ll answer this assuming you ment something like windowF

    Now to your question, the author did pass an array… sort of.
    Presumably blockSwitchingControl is an structure of type BLOCK_SWITCHING_CONTROL. What we’re doing here:

    &blockSwitchingControl->windowF[0][8-1]
    

    is passing the address of windowF’s [0][7]’th element. A multi-dimensional array is linear (continuous) memory so Int32 windowF[2][8] is properly sized for 16 Int32s to be stored in a “row” in memory. Something like:

    windowF[2][8] => [0][1][2][3][4][5][6][7][8][9][A][B][C][D][E][F][10]
    

    Thus, if I were to pass the address of windowF’s [0][7] element, I’m really passing part of the array:

    windowF[0][7]    [0][1][2][3][4][5][6][7][8][9][A][B][C][D][E][F][10]  //full array
              -----------------------------^
    

    So now inside the SrchMaxWithIndex() I have _in[] = an array of Int32’s which is equivalent to part of windowF’s array. So you can see they’re passing an “array’s worth of values”, even if it’s not how you’d expect.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I am writing an app with both english and french support. The app requests

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.