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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:21:49+00:00 2026-05-18T23:21:49+00:00

I am trying my hand out in C and I thought it would be

  • 0

I am trying my hand out in C and I thought it would be prudent to write the following macros:

// takes address of a variable and passes it on as a void*
#define vp_pack(v) ((void*)&x)

// takes a void pointer and dereferences it to t
#define vp_upack(v,t) (*((t*)v))

And I test it out like this:

int
main()
{
    int five = 5;
    char a = 'a';

    vp ptr;

    // Test 1
    ptr = vp_pack(five);
    if(vp_unpack(ptr,int) == five)
        printf("Test 1 passed\n");
    else
        fprintf(stderr, "Test 1: all is doomed\n");

    // Test 2
    ptr = vp_pack(a);
    if(vp_unpack(ptr,char) == a)
        printf("Test 2 passed\n");
    else
        fprintf(stderr, "Test 2: all is doomed!\n");
}

But gcc spews out obscenities like error: expected expression before 'int' at me.

I’ve spent an entire day on this, and still can’t understand, what is wrong with the code. Could any one explain this to me?

Also, I am not a programmer by profession. I don’t even work in IT, but this is my hobby. So if some one could tell me a better way to do this, please do so.

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-05-18T23:21:50+00:00Added an answer on May 18, 2026 at 11:21 pm

    What you did should work, you just have two little typos :

    #define vp_pack(v) ((void*)&v)
    #define vp_unpack(v,t) (*((t*)v))
    

    First line had x instead of v, and second was named vp_upack.

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

Sidebar

Related Questions

I am trying to write a sample code for qt script. I thought I
I've been trying to figure this out for a while so any help would
Just trying to figure out what's the best practice: when using method that takes
After trying my hand at Perl and a little bit of C, I am
I am trying my hand at some AJAX for the first time, and am
I'm trying my hand at behavior driven development and I'm finding myself second guessing
I'm trying my hand in the food industry. I'm going to be developing my
Hurro! I'm trying my hand at writing my first Android app, and I've hit
So, I'm a C# guy trying my hand at learning C. As a first
I'm fairly new to Python, so I'm trying my hand at some simple code.

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.