Skip to content

Commit

Permalink
simplified struct test program for gdb's Pretty Printers.
Browse files Browse the repository at this point in the history
  • Loading branch information
epasveer committed Nov 23, 2023
1 parent 88d8b15 commit 6a56e2b
Showing 1 changed file with 10 additions and 40 deletions.
50 changes: 10 additions & 40 deletions tests/hellopp/hellopp.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
#include <string>
#include <iostream>
#include <string.h>


struct Cell {
unsigned int number;
};

struct Location {
std::string city;
std::string state;
int zip;
struct Cell* cell;
unsigned int cell;
};

struct Person {
Expand All @@ -21,46 +14,23 @@ struct Person {
struct Location location;
};

void print(const Person& person, const Location& where) {

std::cout << "'" << person.name << "' from '" << where.city << "'." << std::endl;
std::cout << "'" << person.name << "' from '" << where.city << "'." << std::endl;
std::cout << "'" << person.name << "' from '" << where.city << "'." << std::endl;
std::cout << "'" << person.name << "' from '" << where.city << "'." << std::endl;
std::cout << "'" << person.name << "' from '" << where.city << "'." << std::endl;
std::cout << "'" << person.name << "' from '" << where.city << "'." << std::endl;
}


int main (int argc, char** argv) {

Person me;
Location where;

me.name = "Pasveer, Ernie";
me.age = 60;
me.salary = 0.25;
me.location.city = "Houston";
me.location.state = "Texas";
me.location.zip = 77063;
me.location.cell = (Cell*)malloc(sizeof(Cell));
me.location.cell->number = 2226669999;

where.city = "Houston";
where.state = "Texas";
where.zip = 77063;
where.cell = (Cell*)malloc(sizeof(Cell));
where.cell->number = 2226669999;
where.cell = 2226669999;

std::cout << "'" << me.name << "', from '" << me.location.city << "', is " << me.age << " years old and makes " << me.salary << " per year." << std::endl;

print(me, where);

free(me.location.cell);
free(where.cell);

me.location.cell = 0;
where.cell = 0;
Person me;
me.name = "Pasveer, Ernie";
me.age = 60;
me.salary = 0.25;
me.location.city = "Houston";
me.location.state = "Texas";
me.location.zip = 77063;
me.location.cell = 2226669999;

return 0;
}
Expand Down

0 comments on commit 6a56e2b

Please sign in to comment.