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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:54:11+00:00 2026-05-30T13:54:11+00:00

I want my function to return a BYTE array. The function is as follows.

  • 0

I want my function to return a BYTE array. The function is as follows.

BYTE sendRecieveData(BYTE control, unsigned int value){

//Open connection to LAC
HANDLE LACOutpipe;
HANDLE LACInpipe;
LACOutpipe=openConnection(MP_WRITE);
LACInpipe=openConnection(MP_READ);

//declare variables
BYTE bufDataOut[3];
BYTE bufDataIn[3];
DWORD bufInProcess;
DWORD bufOutProcess;


//sets CONTROL
bufDataOut[0]=control;

//sets DATA to be sent to LAC
BYTE low_byte = 0xff & value;
BYTE high_byte = value >> 8;
bufDataOut[1]=low_byte;
bufDataOut[2]=high_byte;

MPUSBWrite(LACOutpipe,bufDataOut,3,&bufOutProcess,1000);
MPUSBRead(LACInpipe,bufDataIn,3,&bufInProcess,1000);
MPUSBClose(LACOutpipe);
MPUSBClose(LACInpipe);

return bufDataIn[3];
}

It doesn’t return a byte array and when I change BYTE to BYTE[] or BYTE[3] it gives me an error.

  • 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-30T13:54:12+00:00Added an answer on May 30, 2026 at 1:54 pm

    return bufDataIn[3]; means “return 4th element of bufDataIn array” and in this case it leads to undefined behaviour since the size of this array is 3.

    You can allocate memory for this new array in the body of your function and return pointer to its first element:

    BYTE* createArray(...)
    {
        BYTE* bufDataOut = new BYTE[3];
        ....
        return bufDataOut;
    }
    

    Don’t forget to delete it when you finish with it:

    {
        BYTE* myArray = createArray(...);
        ...
        delete[] myArray;
    }
    

    Even better, use std::vector<BYTE> and get rid of this ugly memory management with it 😉 This ensures that the memory is properly freed on any return path, even when exceptions are thrown.

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

Sidebar

Related Questions

I want a function/code which will return the value that the user submitted for
I want to do something like this: $('.dynamicHtmlForm').validate = function() { return true; }
I want to have a function that will return the reverse of a list
I want to do something like this: class Cls { function fun($php) { return
i want to return wchar_t frm a function. How can i implement it wchar_t
I want to return a set of values from function till the point they
I have 1 function that I want to return the address of an assigned
I want to return ArrayList<HashMap<String,String>> in EL function with three String argument. How to
How do I return a vector in a java function. I want to unserialize
I have a situation where i want to return List<> from this function public

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.