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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:17:37+00:00 2026-05-29T12:17:37+00:00

So I read that in a 32bit machine, one can use the CAS operation

  • 0

So I read that in a 32bit machine, one can use the CAS operation with aligned 64bit blocks.
Similarly, in a 64bit machine, one can use the CAS operation with aligned 128bit blocks.

I’m using a 32bit machine so I tried the following:

// sizeof(long long) is 8 bytes, so 64 bits
long long y = 12;
long long z = 12;
long long x = 99;
__sync_bool_compare_and_swap(&y, z, x);

and the CAS succeeded changing the value of y to 99.

But then I tried using a char array[8];(which size is 64 bits) instead of a long long. And I do:

char full[8] = {'0', '1', '2', '3', '4', '5', '6', '7'}; 
char full2[8] = {'0', '1', '2', '3', '4', '5', '6', '7'};   
char full3[8] = {'5', '8', '9', 'G', 'X', '5', '6', 'U'};
__sync_bool_compare_and_swap(full, full2, full3);  

But in this case, the CAS fails although full and full2 have exactly the same data. (I also checked that full and full2 where correctly alligned)

So the first time it seems that a CAS can be used to 64bit, but the second time it seems it can’t. Any ideas why?

EDIT

(How about 64bit machines?)

Ok, so the problem was that I was using char * in my CAS and these were only checked. So the solution was to cast to long long or to uint64_t which are 64bit values.

But what should I do with a 64bit machine when I need to use 128bit value? long long is still 64bit in a 64bit machine and uint128_t doesn’t seem to exist in C. So to which type should I cast? double long seems to be 128bit in my 64bit machine, but when doing the following:

  double long y = 32432143243214;
  double long z = 32432143243214;

  int x = __sync_bool_compare_and_swap(&y, z, 1234321990);

I get this compile error
error: incompatible type for argument 1 of ‘__sync_bool_compare_and_swap’.

  • 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-29T12:17:42+00:00Added an answer on May 29, 2026 at 12:17 pm

    Looks like you forgot to deref your pointers and cast.

    I tested and this is the only combination that is correct:

    __sync_bool_compare_and_swap((long long*)full, *(long long *)full2, *(long long *)full3);
    

    You need to cast the first param or it will only swap the first char.

    Regarding handling 128-bit double long, this is from the gcc 4.1.2 docs.

    The definition given in the Intel documentation allows only for the
    use of the types int, long, long long as well as their unsigned
    counterparts.
    GCC will allow any integral scalar or pointer type that is 1, 2, 4 or
    8 bytes in length.

    So it would seem you cannot use this function to handle that case.

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

Sidebar

Related Questions

I read that defined styles are located at C:\Program Files\Microsoft Office\Office12\Bibliography\Style I use ISO
Possible Duplicate: Assuming 32bit ints So I read somewhere that int equals int32 in
On the documentation page for Equal we read that Approximate numbers with machine precision
we have a lot of caches that were built on 32bit machine which we
Having already read this question I'm reasonably certain that a given process using floating
I read that you could call JavaScript code from a Java Applet by calling
I read that Domain Driven Design is about concentrating on the problem domain instead
I read that SQL exceptions are treated as normal exceptions in managed SPs; I
I read that you should define your JavaScript functions in the <head> tag, but
I read that some webmail services prefetch url links in emails. The GET request

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.