Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

Millenia Nova

@Millenia Nova
About
Posts
3
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Question about malloc a struct
    M Millenia Nova

    Thank you for clarifying my confusion, Jochen!! :D I appreciate it.

    C / C++ / MFC question graphics help

  • Question about malloc a struct
    M Millenia Nova

    Thanks for your response. Just to make sure I understand your answer, I listed .....I'm thinking the second malloc() used in my previous example can be replaced by the line below?

    sizeof(12 * sizeof(retVal->data));

    Thank you!

    C / C++ / MFC question graphics help

  • Question about malloc a struct
    M Millenia Nova

    The code below uses a variable's type as size in malloc(). And I printf the size of //line 1, b and c to find out their sizes malloc will allocation the space for them in heap. Question part 1: One person told me I should use // line a's size to malloc in // #####, while the other person said I should use //line c instead. They do have the same size in printf(). Which one is correct? Why? Question part 2: // line b and // line c both have the same type of variable pointers, but why do they have different sizes? struct Vector { double *data; size_t size; }; int main() { int a, b, d; int sz = 12; a = sizeof(struct Vector); // line a printf("%d\n", a); //a = 16 b = sizeof(struct Vector*); // line b printf("%d\n", b); //b = 8 c = sizeof(*retVal); // line c printf("%d\n\n", c); //c = 16 struct Vector *retVal = malloc (sizeof (struct Vector)); //##### retVal->data = malloc (sz * sizeof (double)); // Set size and return. retVal->size = sz; printf("retVal->size: %d\n", sz); return 0; } Thank you for your help. :)

    C / C++ / MFC question graphics help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups