Due: Friday, June 28th, 2024 by 10:00 am, No late
exercises accepted.
Goals: Write a program that uses structs, typedef,
and dynamic memory allocation (malloc/free).
Description: Your job is to write a C program that does the following:
Point3d
, which contains uint16_t
fields for
x, y, and z coordinates. AllocatePoint3d
that accepts
three uint16_t
values as arguments, mallocs space for
a Point3d
, assigns
those three arguments to the x, y, and z fields, and returns (a
pointer to) the malloc'ed Point3d
.
AllocatePoint3d
.
For the purposes of this exercise, it is enough for you to write
code that simply allocates a struct by calling
AllocatePoint3d
and verifies that the struct members
contain the correct values. Your "test" should print an appropriate
message if something is wrong; if all is well it's fine to terminate
silently. Make sure your main function frees any memory that
AllocatePoint3d
allocates.
Hint: Don't make assumptions about what
AllocatePoint3d
does, even though you implemented it.
Imagine that your main
is testing an implementation of
AllocatePoint3d
that is implemented by another user.
As usual, your code must:
gcc -Wall -g -std=c17 -o ex3 ex3.c
-- do not
submit a Makefile
.valgrind
)cpplint --clint
.
You should submit your exercise to the course Gradescope.