hi. I want new data type. because it isn't 18 byte. help...
hi. I want new data type. because it isn't 18 byte. help...
You can now declare an instance:Code:typedef char newtype[18];
Code:newtype example="123456789012345678";
Last edited by MK27; 05-16-2009 at 06:13 PM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
<sarcasm>create a struct with an 18-element array of chars</sarcasm>
your question, well you didnt ask a question, your post is extremely vague. because of that you will get vague responses. try again, telling us your detailed question.
Unless you have a 36-bit machine, you won't get an _integral_ type of exactly 18 bits. You can just approximate. Either you take 16 bits or 32. Or use a struct with a bitfield.
Code:typedef struct { unsigned long bits : 18; } ustruct18;
I sorry. Frankly, I have 8 bits mikrocontroller. unsigned long is 32 bits and 4 byte. this is show much. I need 18 bits. I trying " Brafil " code. code is false. tanks...
Then with following declaration in place
Code:unsigned long bits : 18; Is the following assignment okay? bits = 3FFFF; //Will set all the 18 bits.
ThanksCode:incase: if i need only three bits enable for the following statement unsigned int bit :5; Is this assignment correct if i have to set 3 bits? bit=0x07
well that case
Code:typedef struct { unsigned int type : 5; unsigned int bit:3; } ustruct; ustruct bye; Is this assignment correct if i have to set 3 bits? bye.bit=0x07;
And if you union your bits structure with an integer, you will find that setting those three bits will not necessarily set the least significant bits. It MAY do that, but by no means guaranteed. The only way to GUARANTEE bit-order is to use masks and shifts.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Well, okay, they're the three bits that are worth the least that are accessible via the bitfield (which may or may not have any relationship with the underlying integer). If we (that is, the OP) care about the underlying integer/register then using a bitfield is the wrong thing to do (which is probably your point).