A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Curry

  • one year ago

What does the following way of defining a variable mean? #define COUNT ((long) (sizeof(long) <<1))

  • This Question is Closed
  1. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    it's a macro that defines COUNT as the size of a long shifted one bit to the left sizeof(long) = 4 0100 moved one bit to the left 1000 or 8

  2. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    so how do i write macros?

  3. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    like what defines it, how would i write another one if I wanted to? and why not just use a 8 byte variable type.

  4. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    And how exactly would I use the macro? esp seince it's called a function.

  5. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    this one is a variable. macros can also be functions though ``` //taken from http://stackoverflow.com/a/3437442/2761134 #define MAX(a,b) ((a) > (b) ? a : b) #define MIN(a,b) ((a) < (b) ? a : b) ```

  6. e.mccormick
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    https://gcc.gnu.org/onlinedocs/cpp/Macros.html

  7. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Macros are executed by the preprocessor, and they only ever do text replacement. ``` #define MAX(a,b) ((a) > (b) ? a : b) int f() { return MAX(2, 4); } ``` Putting this through the preprocessor will get you something like: ``` int f() { return ((2) > (4) ? 2 : 4); } ``` Which will then later on be compiled. So obviously your macros should only do really simple things. Other languages don't even have this feature, because some consider it dangerous.

  8. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.