Thread: bitmask

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    5

    bitmask

    Hey,

    i have a reg_word, which I'd like to bitmask.
    e.g.
    Code:
    void bitmask(reg_word a) {
      reg_word b = 0xf0;
      reg_word c = (a & b);
    }
    However, I get a segmentation fault. Anybody have an idea where that could come from?

  2. #2
    Registered User Char*Pntr's Avatar
    Join Date
    Sep 2007
    Location
    Lathrop, CA
    Posts
    198
    Quote Originally Posted by zu1u View Post
    Hey,

    i have a reg_word, which I'd like to bitmask.
    e.g.
    Code:
    void bitmask(reg_word a) {
      reg_word b = 0xf0;
      reg_word c = (a & b);
    }
    However, I get a segmentation fault. Anybody have an idea where that could come from?
    What's inside word a?

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by zu1u View Post
    Hey,

    i have a reg_word, which I'd like to bitmask.
    e.g.
    Code:
    void bitmask(reg_word a) {
      reg_word b = 0xf0;
      reg_word c = (a & b);
    }
    However, I get a segmentation fault. Anybody have an idea where that could come from?
    Yep. From somewhere other than that code. More info please.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    A segfault without a pointer in sight - now that's something new.

    Do you have a gdb backtrace to show us?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Sep 2010
    Posts
    5
    the method is called by 3rd party code and I do not really more about it. a is supposedly 32 bit wide and I don't see a pointer, but maybe in the 3rd party code?
    I'm not really an experienced C coder, I don't know how I could do a gdb backtrace.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Run the code in the debugger.
    gdb ./myprog

    Then type 'run' at the prompt.

    When it crashes, type 'bt' and post what it prints.

    > I'm not really an experienced C coder
    Is there anyone near to you that is?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Sep 2010
    Posts
    5
    I did it differently now: Shift first, and then bitmask. Now it does work for some reason.
    Thanks for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. get visible mouse cursor height
    By eXistenZ in forum Windows Programming
    Replies: 10
    Last Post: 09-05-2008, 09:46 PM
  2. Binary Converter - Various stupid string issues :p
    By polarpete in forum C++ Programming
    Replies: 7
    Last Post: 08-21-2005, 02:46 PM
  3. bitmask
    By potbelle in forum C Programming
    Replies: 3
    Last Post: 03-31-2002, 08:09 AM