구조체 질문입니다.

살자의 이미지

구조체에서

typedef struct
{
    TUBIT32 cReserved       :   3;
    TUBIT32 bBufferAging    :   1;
}Test

콜론을 사용하면 어떻게 작동하는지 궁금합니다.
서지훈의 이미지

int a : 1; 이 선언은 a를 1bit만 사용을 하겠다는 의미입니다. 만약에 연이어서... int b : 1; 를 선언 하게 되면은 int 의 사이트 안에 a, b 를 다 포함이 가능하기 때문에 여전히 두 변수는 int - 4byte 안에 값이 선언되고 사용이 되게 됩니다.

만약 a and b를 16-bit 보다 크게 선언을 하게 되면은 각각 다른 int - 4byte에 선언이 되게 됩니다.
그러므로 8-byte를 사용하게 됩니다.

<어떠한 역경에도 굴하지 않는 '하양 지훈'>

#include <com.h> <C2H5OH.h> <woman.h>
do { if (com) hacking(); if (money) drinking(); if (women) loving(); } while (1);

카二리의 이미지

요게... 좀 저두 해깔리는 문법이긴 한대...

일단 아는걸 풀어 놓자면..

이녀석의 문법은 다음과 같습니다.

[타입]    <이름>    :    [const 수식]    ;

이런 식인대요-_-
이녀석의 쓰임세는 스트럭쳐 안을 각각의 bit별로 조작하려고 쓰는대요.
일단 array,address, pointer, reference(C++에서) 가 모두 안됩니다.
그리고 최대로 다룰수 있는 비트 수는 컴파일러마다 틀리지만 호환성 유지를 위해 32비트 까지만 쓰는걸로 알고 있습니다.
또 int 씨리즈 (unsigned, signed) 만 써야 합니다.(이건 정확히 모르겠네요-_-; )

또한 이름은 없어도 되고-_-; 각 32비트로 정렬이 됩니다.
게다가 0비트 일 경우는 반드시 이름이 없어야 하고 또 초기화할수도 없고 레퍼런싱 할수도 없습니다.
이게 무슨말인고 하니

struct S{
    int a : 1;
    int b : 1;
    int : 0;
    unsigned : 3;
    int c ;
} s

요럴 경우에 a는 1비트 b는 1비트 그다음 이름없는 0비트 에서 32-2 해서 30비트가 빈공간으로 넘어갑니다. 그다음 이름없는 공간에 3비트 C에 int 사이즈만큼.
이렇게 잡힙니다-___-;

자세하게 저도 몰라서 두서없이 쓰게 된듯-_-;

다른분이 좀더 자세하게 올려주시면 쿨럭..

새 생각 :)

카二리의 이미지

새 생각 :)

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.