32byte 보다 struct 사용시 에러 질문입니다. on gcc

fantagia의 이미지

struct  kk{
        int a;
        int b;
        unsigned int c;
        int d;
        int e;
        int f;
        int g;
        int h; // 이 라인에서 에러가 찍힙니다.
        int i;
        int j;
};

8번째 int값에서 꼭 에러가 납니다.
에러 내용은 이렇습니다.
expected ':', ',', ';' ,'}' or '__attribute__' before '.' token

7번째 int값까지 찍고 나서 8번째에 뭐라고 쓰든지간에 꼭 에러가 납니다.

구글링을 한참 했지만 잘 모르겠어서 이렇게 질문글을 올립니다.

구글링 결과

1>
매크로 괄호를 안닫아서 그렇다는 소리가 있는데 그건 잘 했습니다.

2>
__attribute__ ((packed)) 를 사용하라고 써있는데

int 1개
char 1개
일때 5byte만 사용하도록 하는 것인것 같아서 제 상황이랑은 좀 다른 것 같습니다.

꼭 8번째 int에서부터 그러는 것이 구조체는 32bit word 를 넘는 사이즈는 안되는 건가 싶어서
찾아봤는데 이렇게 무식하게 큰 구조체 예제는 거의 없네요

이게 실은 man 2 stat 하면 나오는 stat 구조체와 비슷하게 만들어야 되는데
struct stat 은 있는데 왜 제 것은 에러가 나는지 모르겠습니다.

include/sys/stat.h 를 열어봐도

man 2 stat 에서 설명나오는 struct stat은 안나오고
매크로만 많이 나와서 참고하기 힘듭니다.

3번은

이해하기는 int a는 2바이트 할당하고
int b는 4바이트 할당하는 것이라고 생각했는데
맞는지 확실히 모르겠습니다.

추가로
이게 GCC라서 에러 나는 것 같기도 한데
GCC 공부하려면 무슨 책 or 문서 보는 게 좋을까요.

여러 고수분들의 도움 부탁드립니다.

ymir의 이미지

저런 조그만 struct 에 문제가 있을 것 같지는 않네요.
소스 어딘가에 오타나 빠트린게 있을 겁니다.
에러 난 부분 위쪽으로 코드를 꼼꼼하게 살펴보세요.

간혹, type 에 따라 include 해야 하는 헤더가 있는데..
빠트린 경우에도 비슷하게 파싱 에러가 날 수 있습니다.

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

qiiiiiiiip의 이미지

ymir님 말씀대로 에러는 보여주신 부분이 아닌 다른 부분에 있습니다.
그래서 보통 에러가 재현되는 최소한의 소스코드를 올리라고 합니다.
그렇게 찾다보면 자연스럽게 디버깅이 됩니다.

말씀하신 에러는 이런 경우에 재현이 되네요..

$ cat main.c
struct  kk{
    int a.;
    int b;
};
 
int main()
{
    return 0;
}
 
$ gcc main.c
main.c:2: error: expected ':', ',', ';', '}' or '__attribute__' before '.' token

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.