Thread: 128 bit uchar array? please help

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    40

    128 bit uchar array? please help

    Hi I need a 128 bit int-like data type. I was told to use code like this:

    Code:
    uchar hash[0];
    Apparently the compiler will know it's 128 bits at compile-time? Anyways, what's the most elegant way to represent 128-bit array? Thanks

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Hah. uchar is one byte, not sixteen. Maybe you were told to use uchar hash[16].

    Anyway, if there is a built-in type, check stdint.h; you'll see a uint128_t (note: you almost certainly won't). Otherwise, you'll have to make an array of the right length yourself. (Which data type you use depends on why you want 128-bits. If you're going to do things on a byte-by-byte basis, uchar is fine; if you plan to do some math, using the natural int might be a better choice.)

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    40
    okay. I actually misinterpreted the semantics of the code. I was actually told to use

    Code:
    uchar hash_code[0];
    as a pointer, and then use that to malloc 128 bits. Apparently it's more proper than a (void *)...

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    If you want a pointer, declare a pointer, not an array of size 0.

  5. #5
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by brooksbp View Post
    Apparently it's more proper than a (void *)...
    There's nothing improper about using a void * it's there as a generic pointer type. if you want something that just *looks* more proper, use typedef.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. convert 32 bit number to array of digits
    By droseman in forum C Programming
    Replies: 11
    Last Post: 02-18-2009, 09:37 AM
  2. array of pointers/pointer arithmetic
    By tlpog in forum C Programming
    Replies: 18
    Last Post: 11-09-2008, 07:14 PM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  5. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 12:44 AM