From 8d5eed3c82fa6f59c4f9d860f1d5c6bbdd837d80 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Wed, 8 Jul 2020 18:07:50 -0700 Subject: Convert Fl_Group::array_ to union to better represent its behavior Amended by Albrecht: - rename union member variables as discussed - add comments to new array_ union members Fixes #96 Signed-off-by: Albrecht Schlosser --- src/Fl_Group.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Fl_Group.cxx b/src/Fl_Group.cxx index 4a614e1e4..769d28600 100644 --- a/src/Fl_Group.cxx +++ b/src/Fl_Group.cxx @@ -38,7 +38,7 @@ Fl_Group* Fl_Group::current_; is added or removed. */ Fl_Widget*const* Fl_Group::array() const { - return children_ <= 1 ? (Fl_Widget**)(&array_) : array_; + return children_ <= 1 ? &child1_ : array_; } /** @@ -473,9 +473,9 @@ void Fl_Group::insert(Fl_Widget &o, int index) { } o.parent_ = this; if (children_ == 0) { // use array pointer to point at single child - array_ = (Fl_Widget**)&o; + child1_ = &o; } else if (children_ == 1) { // go from 1 to 2 children - Fl_Widget* t = (Fl_Widget*)array_; + Fl_Widget* t = child1_; array_ = (Fl_Widget**)malloc(2*sizeof(Fl_Widget*)); if (index) {array_[0] = t; array_[1] = &o;} else {array_[0] = &o; array_[1] = t;} @@ -520,7 +520,7 @@ void Fl_Group::remove(int index) { if (children_ == 1) { // go from 2 to 1 child Fl_Widget *t = array_[!index]; free((void*)array_); - array_ = (Fl_Widget**)t; + child1_ = t; } else if (children_ > 1) { // delete from array for (; index < children_; index++) array_[index] = array_[index+1]; } -- cgit v1.2.3