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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:52:21+00:00 2026-05-19T00:52:21+00:00

I see a code as below: #include stdio.h #define VECTOR_SIZE 4 typedef float v4sf

  • 0

I see a code as below:

#include "stdio.h"

#define VECTOR_SIZE         4
typedef float v4sf __attribute__ ((vector_size(sizeof(float)*VECTOR_SIZE))); 
 // vector of four single floats

typedef union f4vector
{
    v4sf    v;
    float   f[VECTOR_SIZE];
} f4vector;

void print_vector (f4vector *v)
{
    printf("%f,%f,%f,%f\n", v->f[0], v->f[1], v->f[2], v->f[3]);
}

int main()
{
    union f4vector a, b, c;

    a.v = (v4sf){1.2, 2.3, 3.4, 4.5};
    b.v = (v4sf){5., 6., 7., 8.};
    c.v = a.v + b.v;

    print_vector(&a);
    print_vector(&b);
    print_vector(&c);
}

This code builds fine and works expectedly using gcc (it’s inbuild SSE / MMX extensions and vector data types. this code is doing a SIMD vector addition using 4 single floats.

I want to understand in detail what does each keyword/function call on this typedef line means and does:

typedef float v4sf __attribute__ ((vector_size(sizeof(float)*VECTOR_SIZE))); 

What is the vector_size() function return;

What is the __attribute__ keyword for

Here is the float data type being type defined to vfsf type?

I understand the rest part.

thanks,

-AD

  • 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-19T00:52:22+00:00Added an answer on May 19, 2026 at 12:52 am

    __attribute__ is GCCs way of exposing functionality from the compiler that isn’t in the C or C++ standards.
    __attribute__((vector_size(x))) instructs GCC to treat the type as a vector of size x. For SSE this is 16 bytes.

    However, I would suggest using the __m128, __m128i or __m128d types found in the various <*mmintrin.h> headers. They are more portable across compilers.

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

Sidebar

Related Questions

See code below, for some reason it only works when I put a breakpoint
How come unserialize isn't restoring my array? See code below.. // prints a:1:{s:8:txn_type;s:32:recurring_payment_profile_cancel;} echo
I have a table defined (see code snippet below). How can I add a
EDIT: See my working code in the answers below. In brief: I have a
Update: Solved, with code I got it working, see my answer below for the
I can't get the code below to compile (see errors). Advice on correction would
See code: var file1 = 50.xsl; var file2 = 30.doc; getFileExtension(file1); //returns xsl getFileExtension(file2);
I often see code like: Iterator i = list.iterator(); while(i.hasNext()) { ... } but
I have see code like this Dim s as something = new something Dim
I'm still learning ASP.NET and I often see code like this throughout parts of

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.