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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:13:58+00:00 2026-06-06T00:13:58+00:00

I have defined the following struct in C: typedef struct point{ float x; float

  • 0

I have defined the following struct in C:

typedef struct point{
    float x;
    float y;
    float z;
} Point;
typedef Point Vector;

and the following macro:

#define sub(p1,p2)      {p1.x-p2.x,p1.y-p2.y,p1.z-p2.z}

That is used like this:

void fun(Point p0, Point p1){
    Vector u;
    u=sub(p1,p0);
}

From what I’ve read this should work, or maybe I’m missing something maybe even obvious… but I’m getting the following error that I don’t understand what I’m supposed to look do:

error: expected expression before '{' token

So basically I just want to obtain the same as:

struct point u={p1.x-p0.x,p1.y-p0.y,p1.z-p0.z}

I really have no idea of what am I doing wrong…
Thank you.

[EDIT]
included some more function details so you can see where I think my mistake was. Not initializing with the variable declaration because after changing

Vector u;
u=sub(p1,p0);

to

Vector u=sub(p1,p0);

It works but I still don’t understand why.

  • 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-06T00:14:01+00:00Added an answer on June 6, 2026 at 12:14 am

    This has nothing to do with the macro: the problem would persist even if you expand this macro by hand. The reason why this is failing is that initializer list in an assignment must be composed of constant expressions, so p1.x is not allowed.

    If you are using C99, change your macro to use a compound literal, like this:

    #define sub(p1,p2)      (Vector){p1.x-p2.x,p1.y-p2.y,p1.z-p2.z}
    

    This will let you use the macro in assignments as well as in initializers.

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

Sidebar

Related Questions

I have the following code //Point.h #define WIDTH 8 #define HEIGHT 8 typedef struct
I'm trying to read the bitmap header. I have defined the following struct: typedef
I have a struct defined as the following: typedef struct { string foo; }
I have a structure defined like so: typedef struct { int n; int *n_p;
I have a struct as defined by the following: typedef struct { NSString *SportName;
I have a struct A that is defined as follows: typedef struct A {
Why I'm asking this is because following happens: Defined in header: typedef struct PID
I have defined the following ApplicationManifest file the problem is that i have created
in header file I have defined the following function #ifndef OS_H #define OS_H #include
I have set up the following struct: typedef struct _thread_node_t { pthread_t thread; struct

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.