[過去ログ] 【まず1嫁】くだすれPython(超初心者用) その59 (1002レス)
前次1-
抽出解除 必死チェッカー(本家) (べ) 自ID レス栞 あぼーん

このスレッドは過去ログ倉庫に格納されています。
次スレ検索 歴削→次スレ 栞削→次スレ 過去ログメニュー
714
(1): デフォルトの名無しさん [sage] 2024/06/22(土) 18:07:00.66 ID:n3FOHUyg(1) AAS
>>710
710(1): デフォルトの名無しさん [sage] 2024/06/22(土) 13:39:16.54 ID:o/eWDsQ7(1) AAS
>>688 への回答として >>693 は全く不適切
判っててわざと間違ってるんだろうが全く別物
初心者に嘘を教えるのは良くない
外部リンク:ideone.com

#include <stdio.h>
#include <stdlib.h>
int x;
struct A {
int a;
int b[];
};
struct B {
int a;
int *b;
};
int main(void) {
printf("%zu\n", sizeof(x));
printf("%zu\n", sizeof(struct A));
printf("%zu\n", sizeof(struct B));
struct B b = {0};
b.b = (int *)malloc(4 * sizeof(int));
free(b.b);
/*
struct A a = {0};
a.b = (int *)malloc(4 * sizeof(int)); // compile error
free(a.b); // don't free (may be cause to runtime error)
*/
return 0;
}
flexible array memberの基本的な使い方も知らないのに
無理してレスしなくてもよくない?

C側でメモリ確保したいならこう書くんだよ
struct A *a = malloc(sizeof(struct A) + size * sizeof(int));

>>693
693(3): デフォルトの名無しさん [sage] 2024/06/20(木) 18:12:29.06 ID:pudWG0gF(1) AAS
>>688
("wOdList", POINTER(c_uint16))

a = aa()
a.wOdList = (c_uint16 * size)()

wResがwOdListのsizeだったりするのかな?
のa.wOdList = (c_uint16 * size)()はPython側でメモリ確保する場合の話だよ
CとPythonでやり取りする時はflexible array memberのsizeも当然受け渡しする必要があるよ

こんなんで大丈夫かな?
前次1-
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル

ぬこの手 ぬこTOP 0.040s