Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

缺乏类型检查,什么都可以往里塞。 #49

Open
fastfading opened this issue Dec 11, 2020 · 1 comment
Open

缺乏类型检查,什么都可以往里塞。 #49

fastfading opened this issue Dec 11, 2020 · 1 comment

Comments

@fastfading
Copy link

缺乏类型检查,什么都可以往里塞。
编译不报错,连warning也不报。

运行时报错

 vector_t *pvec_strptr = create_vector(string_t);
 vector_init(pvec_strptr);
 string_t *pstr1 = create_string();
 string_init(pstr1);
 string_assign_cstr(pstr1, "abc");
 vector_push_back(pvec_strptr, pstr1);
 vector_push_back(pvec_strptr, "123");
 vector_push_back(pvec_strptr, 123);
 vector_push_back(pvec_strptr, NULL);
 string_t *pstr2 = (string_t *)vector_at(pvec_strptr, 0);
 printf("%s ", string_c_str(pstr2));
 vector_destroy(pvec_strptr);
@fastfading
Copy link
Author

fastfading commented Dec 11, 2020

下面这个更神奇
运行都不报错

  vector_t *pvec_charptr = create_vector(int);
    vector_init(pvec_charptr);
    char *p;
    short *q = NULL;
    vector_push_back(pvec_charptr, p);
    vector_push_back(pvec_charptr, q);
    vector_push_back(pvec_charptr, "ABC");
    vector_push_back(pvec_charptr, 123);
    vector_push_back(pvec_charptr, NULL);
    vector_destroy(pvec_charptr);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant