目次

ニュース

日記カテゴリ

書庫

ふと基本情報技術者くらい受けておくかぁ、と思いむたぐちさんPowerShell本と共に基本情報技術者の本を買いましたとさ。

で、アルゴリズムのページなんか見ているとちょっと書きたくなってCコンパイラを用意w

とりあえずソートでも書いてみるかぁ、なんて書き始めたんですがいやぁ普段.Netだと書けない書けないw

「配の長さって・・・、え?w」みたいな感じです。

結局は分かりましたけどね。

sizeof(配列) / sizeof(配列[0])

と、ここで更につまづく。
コマンドライン引数で取って来たもの、もしくはexternを付けたりすると長さが取れない!ということにwikipediaをみて気づく。

それで分かりました。int argcを取るコマンドライン引数で取る理由が。
それ以外で配列長を求められなかったのね。
投稿日時 : 2008年5月20日 16:08
Feedback
  • # re: [C言語] 配列の長さを求める
    めたぼ なら
    Posted @ 2008/05/20 16:15
    > sizeof(配列) / sizeof(配列[0])
    これって確か処理系依存だったような...
    # 昔えムナウさんが似たようなことをどっかで書いてたような。

    なので、配列のサイズはconstとかで固定しときましょうってのが良いんぢゃなかろうかと...
  • # re: [C言語] 配列の長さを求める
    シャノン
    Posted @ 2008/05/20 16:34
    JIS X 3010にも、sizeof の使い方として、配列の要素数を求めるのは書いてありますけどね。
  • # re: [C言語] 配列の長さを求める
    ma2
    Posted @ 2008/05/20 16:54
    mallocで動的に確保したものも求められませんよね。
    昔聞かれて解決できなかった思い出が。
  • # re: [C言語] 配列の長さを求める
    taka
    Posted @ 2008/05/20 17:07
    > めたぼさん
    > なので、配列のサイズはconstとかで固定しときましょうってのが良いんぢゃなかろうかと...
    以前Pro*Cやりましたけどそのときもそんなことしてましたねー。

    > シャノンさん
    > JIS X 3010にも、sizeof の使い方として、配列の要素数を求めるのは書いてありますけどね。
    やっぱ定石なんかな。

    >ma2さん
    そうそう、それも出来ないですね。
    つまりコンパイル時に決まらんとダメっぽい。
    #つかコンパイル時に測値になるから当たり前か。
    #wikipeida調べ
  • # re: [C言語] 配列の長さを求める
    めたぼ なら
    Posted @ 2008/05/20 17:44
    > JIS X 3010にも、sizeof の使い方として、配列の要素数を求めるのは書いてありますけどね。
    そなんや。
    ぢゃ、いいのかな。

    で、えムナウさんの記事見っけ。
    http://blogs.wankuma.com/mnow/archive/2007/02/17/62748.aspx

    これって、悪影響ないんかなぁ。
    # 普通の配列なら大丈夫か。
  • # re: [C言語] 配列の長さを求める
    taka
    Posted @ 2008/05/20 17:57
    あぁ、そうそうポインタを渡すとポインタのサイズが変える。
    例えばsizeof(char*)、で32bitだと4で、16bitだと2。
    文字列配列の配列長ならそのままいけるけど、文字列長だとターミネータ来るまで走査しないとだめっぽいのね。
    #いや、本当にそうか?w試してないから分かりまへん(?-?)
  • # re: [C言語] 配列の長さを求める
    とっちゃん
    Posted @ 2008/05/20 18:20
    TCHAR[] a="123\0567";
    sizeof(a) としてみると、文字列長と配列の長さの違いがわかります。

    もちろん、_tcslen(a); との比較もしないとだめですがw
  • # re: [C言語] 配列の長さを求める
    出水
    Posted @ 2008/05/20 18:46
    char a[] = "test";
    えムナウさんの時代はこの書き方が出来なかったんじゃないかなぁと推測

    ちなみに、昔のC++はdelete[]に引数が必要だったんですよ
    char *a = new char[100];
    delete [100] a;

    で、今は引数いらないから長さを隠し持っているわけですが、
    隠し持ってるなら教えてくれてもいいよねってepiさんに聞いたら
    確保と開放に必要な情報と長さ情報は違う、ってな事を言われたような気がします

    で…考えた結果…
    ・1kBのバッファと空き容量とカウンタを確保
    ・newのたびにカウンタ++,deleteでカウンタ--
    ・カウンタが0になったときのみバッファ全体を開放済みとして扱う
    みたいな管理だと、個々の長さ情報はわからないですのでこういうことじゃないかなーとか
  • # re: [C言語] 配列の長さを求める
    taka
    Posted @ 2008/05/20 18:57
    > とっちゃん
    TChar[]って事はマルチバイト?
    あと、_tcslen()に関しては全く分かりません。
    見た感じ、文字列長を返しそうな感じですが。

    > 出水さん
    C++は書いたことないからいまいちピンとこないですねー
    特に
    > で・・・考えた結果・・・
    のくだりのところ。
  • # re: [C言語] 配列の長さを求める
    めたぼ なら
    Posted @ 2008/05/20 19:02
    > char a[] = "test";
    これは初版のK&Rでも書けてたよ。

    # なんかごめん、私のコメントきっかけで脱線させちゃった。
  • # re: [C言語] 配列の長さを求める
    taka
    Posted @ 2008/05/20 19:03
    > めたぼさん
    別にかまへんですよー
    こんな流れで余分な知識が蓄積されるのですw
    #そして必要なときは余分な知識でなくなる
  • # re: [C言語] 配列の長さを求める
    とっちゃん
    Posted @ 2008/05/20 19:09
    TCHAR は、UNICODE だと wchar_t、 SBCS/MBCS だと char になる、#define です。
    _tcslen は strlen の TCHAR 版です。

    これから先、Windows 系で C/C++ をやるならまず最初に把握しておくべきところですね。
    Unix 系はどういう扱いになってるか知らんですがw
  • # re: [C言語] 配列の長さを求める
    出水
    Posted @ 2008/05/20 21:35
    >めたぼさん
    char a[] = "test";
    sizeof("test"); → sizeof(char*);
    この二つが両立しているコンパイラはあるんですかね?って意味です
    素人考えだと、"test"がchar[5]を返すから配列サイズが確定するんだと思ったんですが…
  • # re: [C言語] 配列の長さを求める
    めたぼ なら
    Posted @ 2008/05/20 22:01
    出水さん
    > この二つが両立しているコンパイラはあるんですかね?って意味です

    それって、えムナウさんの記事と同じ話?
    それとも、またわたし迷子になっちゃった?

    > 素人考えだと、"test"がchar[5]を返すから配列サイズが確定するんだと思ったんですが…

    それでOKだと思います。
    char[5]って、charのサイズ×5って意味であれば。

    # ごめんよぉ~。>みなさま。私が惑わすようなコメントをしたばっかりに。
    # takaさんの記事はそれ単体でOKで、私が脱線させちゃいました。
  • # re: [C言語] 配列の長さを求める
    とっちゃん
    Posted @ 2008/05/20 22:17
    あ、今気付いた...
    TCHAR a[] = "..."; じゃなくて
    TCHAR a[] = TEXT("...");

    TCHAR a[] = _T("...");
    じゃないとダメっす。<最初のコメント

    と、KYなことを書いてみるw
  • # S品グッチ
    rfjnaiufwzb@icloud.com
    Posted @ 2017/07/13 12:31
    ★弊社は「信用第一」をモットーにお客様にご満足頂けるよう
    ★全物品運賃無料(日本全国)
    ★不良品物情況、無償で交換します.
    ★税関没収する商品は再度無料で発送します
    S品グッチ http://www.nawane111.com
  • # ルイヴィトンコピーバッグ
    vlrvqgdgzc@excite.co.jp
    Posted @ 2017/08/16 15:04
    日本的な人気と信頼を得ています。
    安心、安全にお届けします
    価格、品質、自信のある商品を取り揃えておりますので、
    当店の主要な経営のブランド:ヴィトン シャネル ロレックスなど.
    当店は主に経営する商品:かばん.バッグ .財布 .キーケース. .腕時計など.
    日本には無い商品,日本では高価な商品,弊社のない商品,取引先を代理して製造会社を連絡することができる.
    弊社長年の豊富な経験と実績があり.輸入手続も一切は弊社におまかせできます.ご希望の商品を責任を持ってお届けします.
    当店の商品は特恵を与える。興味あれば、是非ご覧下さい
    財布、腕時計、バッグ一品市場
    ルイヴィトンコピーバッグ http://www.nawane111.com
  • # ロレックス最高品質時計
    uusslteedjg@ezwen.ne.jp
    Posted @ 2017/08/30 16:36
    大量在庫超人気の新しい2017年!
    ☆――☆ブランドバッグ☆――☆
    ☆――☆ブランド服コピー☆――☆
    ☆――☆ブランド靴コピー ☆――☆
    ※―――※―――※―――※―――※
    ルイヴィトン靴コピー,エレメス靴
    ルブタン コピー,シャネル靴コピー
    バーバリー靴コピー,クロムハーツ靴
    ※―――※―――※―――※―――※
    ①高品質、特恵価格、実物写真、納期厳守。
    ②お客様の満足することは 弊社の責任です。
    それでは不良品物情況、無償で交換します。
    ③配送方法 : 全物品運賃無料(日本全国)
    ※―――※―――※―――※―――※
    営業時間:24時間、年中無休
    オンライン連絡時間:平日8時から18時まで
    ☆――☆――☆――☆――☆――☆
    ロレックス最高品質時計 http://www.kopii.net/products/p3/3/index.htm
  • # I know this web site gives quality depending posts and other material, is there any other web site which offers these stuff in quality?
    I know this web site gives quality depending posts
    Posted @ 2021/08/30 17:05
    I know this web site gives quality depending posts and other material, is there any other web site which offers these stuff
    in quality?
  • # Today, I went to the beach front with my children. I found a sea shell and gave it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She put the shell to her ear and screamed. There was a hermit crab ins
    Today, I went to the beach front with my children.
    Posted @ 2021/09/01 22:58
    Today, I went to the beach front with my children. I found a sea shell and gave
    it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She put the shell to her ear and screamed.
    There was a hermit crab inside and it pinched her ear.

    She never wants to go back! LoL I know this is totally off topic but I had to tell someone!
  • # Today, I went to the beach front with my children. I found a sea shell and gave it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She put the shell to her ear and screamed. There was a hermit crab ins
    Today, I went to the beach front with my children.
    Posted @ 2021/09/01 22:59
    Today, I went to the beach front with my children. I found a sea shell and gave
    it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She put the shell to her ear and screamed.
    There was a hermit crab inside and it pinched her ear.

    She never wants to go back! LoL I know this is totally off topic but I had to tell someone!
  • # Today, I went to the beach front with my children. I found a sea shell and gave it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She put the shell to her ear and screamed. There was a hermit crab ins
    Today, I went to the beach front with my children.
    Posted @ 2021/09/01 23:00
    Today, I went to the beach front with my children. I found a sea shell and gave
    it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She put the shell to her ear and screamed.
    There was a hermit crab inside and it pinched her ear.

    She never wants to go back! LoL I know this is totally off topic but I had to tell someone!
  • # Today, I went to the beach front with my children. I found a sea shell and gave it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She put the shell to her ear and screamed. There was a hermit crab ins
    Today, I went to the beach front with my children.
    Posted @ 2021/09/01 23:01
    Today, I went to the beach front with my children. I found a sea shell and gave
    it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She put the shell to her ear and screamed.
    There was a hermit crab inside and it pinched her ear.

    She never wants to go back! LoL I know this is totally off topic but I had to tell someone!
  • # I am genuinely delighted to read this web site posts which contains tons of valuable information, thanks for providing such data.
    I am genuinely delighted to read this web site pos
    Posted @ 2021/09/05 21:44
    I am genuinely delighted to read this web site posts which contains tons of
    valuable information, thanks for providing such data.
  • # I am genuinely delighted to read this web site posts which contains tons of valuable information, thanks for providing such data.
    I am genuinely delighted to read this web site pos
    Posted @ 2021/09/05 21:45
    I am genuinely delighted to read this web site posts which contains tons of
    valuable information, thanks for providing such data.
  • # I am genuinely delighted to read this web site posts which contains tons of valuable information, thanks for providing such data.
    I am genuinely delighted to read this web site pos
    Posted @ 2021/09/05 21:46
    I am genuinely delighted to read this web site posts which contains tons of
    valuable information, thanks for providing such data.
  • # I am genuinely delighted to read this web site posts which contains tons of valuable information, thanks for providing such data.
    I am genuinely delighted to read this web site pos
    Posted @ 2021/09/05 21:47
    I am genuinely delighted to read this web site posts which contains tons of
    valuable information, thanks for providing such data.
  • # Hmm is anyone else experiencing problems with the images on this blog loading? I'm trying to find out if its a problem on my end or if it's the blog. Any feedback would be greatly appreciated. quest bars http://bitly.com/3C2tkMR quest bars
    Hmm is anyone else experiencing problems with the
    Posted @ 2021/09/11 22:15
    Hmm is anyone else experiencing problems with the images on this blog loading?
    I'm trying to find out if its a problem on my end or if it's
    the blog. Any feedback would be greatly appreciated.
    quest bars http://bitly.com/3C2tkMR quest bars
  • # Hurrah! After all I got a website from where I know how to genuinely get useful data concerning my study and knowledge. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars
    Hurrah! After all I got a website from where I kno
    Posted @ 2021/09/14 16:53
    Hurrah! After all I got a website from where I know how to genuinely get useful data concerning my
    study and knowledge. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars
  • # Hurrah! After all I got a website from where I know how to genuinely get useful data concerning my study and knowledge. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars
    Hurrah! After all I got a website from where I kno
    Posted @ 2021/09/14 16:54
    Hurrah! After all I got a website from where I know how to genuinely get useful data concerning my
    study and knowledge. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars
  • # Hurrah! After all I got a website from where I know how to genuinely get useful data concerning my study and knowledge. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars
    Hurrah! After all I got a website from where I kno
    Posted @ 2021/09/14 16:55
    Hurrah! After all I got a website from where I know how to genuinely get useful data concerning my
    study and knowledge. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars
  • # Hurrah! After all I got a website from where I know how to genuinely get useful data concerning my study and knowledge. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars
    Hurrah! After all I got a website from where I kno
    Posted @ 2021/09/14 16:56
    Hurrah! After all I got a website from where I know how to genuinely get useful data concerning my
    study and knowledge. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars
タイトル
名前
Url
コメント 

Blog 利用状況