ページ 11

about the "C struct pointer"

Posted: 2013年8月05日(月) 14:43
by ubuntuooo
皆さん、こんにちは!

下記のように構造体ポインターの初期化についてご教授お願いしたいです。

コード:

struct s_time{
  short year;
  char month;
  char day;
};

void main(){

  struct s_time *p_time;
  p_time = &s_time; ★??
......
}


Re: about the "C struct pointer"

Posted: 2013年8月05日(月) 14:55
by ubuntuooo
★付いている箇所は 初期化処理でしょうか?
初期化処理であればどういうことでしょうか?
いろいろ探しましたが、理解できませんでした。TT

Re: about the "C struct pointer"

Posted: 2013年8月05日(月) 15:05
by softya(ソフト屋)
たしかに変だと思います。
このコードはコンパイルを通りません。
s_timeが何処かで変数定義されている必要があります。

これなら通ります。

コード:

struct s_time{
  short year;
  char month;
  char day;
};

static struct s_time s_time;

void main(){
 
  struct s_time *p_time;
  p_time = &s_time;// ★??

}

Re: about the "C struct pointer"

Posted: 2013年8月05日(月) 15:18
by usao
事態が不明瞭です.
まず,そのコードはどこから出てきたものなのでしょうか?

#単に型名とインスタンスとの区別がついていないだけにも見えますが…

Re: about the "C struct pointer"

Posted: 2013年8月05日(月) 15:45
by ubuntuooo
[quote="usao"]事態が不明瞭です.
まず,そのコードはどこから出てきたものなのでしょうか?
ごめん、あるシステムソースです。
セキュリティの原因で明確的に載せてはいけません。。。

Re: about the "C struct pointer"

Posted: 2013年8月05日(月) 16:02
by softya(ソフト屋)
丁寧語を使ってくだると助かります。
ソースが部分的にしか明示されないのであれば、明快な回答は困難かと思います。

Re: about the "C struct pointer"

Posted: 2013年8月05日(月) 17:50
by ubuntuooo
わかりました。ソース全体として確認します。
ありがとうございます。