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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:34:25+00:00 2026-06-15T23:34:25+00:00

I need to pass some structure as function argument like this void myFunc(unsigned char

  • 0

I need to pass some structure as function argument like this

void myFunc(unsigned char c);

I will use myFunc(4), myFunc(8) or so.

Now the function accepts a structure as argument, so I tried

typedef struct {
    unsigned char address;
    unsigned char command;
    unsigned char group;
    unsigned char response;
    unsigned char flags1;
    unsigned char flags2;
}test_t;

void myFunc(test_t test);

myFucn({0,0,0,0,0}); // but this gives me error 

How can I pass const struct as argument without to have to instantiate first ?
Just like myFunc(4) as unsigned char.

Thanks

  • 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-15T23:34:26+00:00Added an answer on June 15, 2026 at 11:34 pm

    In C99, you can use a compound literal:

    myFunc((test_t) { 0, 0, 0, 0, 0 });
    

    Of course, since the struct is being passed by value, it doesn’t matter if you consider it to be “const” or not; whatever the function does to it won’t matter to the outside.

    In previous versions of C, you cannot do this.

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

Sidebar

Related Questions

I am writing some and I need to pass a complicated data structure to
I have some function where I need to pass a point datatype . somefunc(United
I'm writing a web application where I need to pass some user data to
I need to find a way to pass some strings to my word 2003
I've some scenarios where i need to pass value type as reference without changed
I need to pass '+' via the QueryString . some special character can be
I am writing some kind of IPC functionality and need to pass certain resources
I have some .net dll's and Exe's. I need to pass MSIL files to
I need some additional functionality added to user_pass_submit. This must be added without changing
I need to use a big data structure, more specifically, a big dictionary to

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.