Skip to content

DateTime class accepts type-conflicting assignments #76

Description

@IowaDave

Requesting input from C++ experts regarding a puzzling behavior of the DateTime class as defined in this DS3231.h.

In Arduino IDE 1.8.15, at least, the following assignment ("=" operator) compiled and executed without error or any warning related to type mismatch between the LH and RH operands.

#include <DS3231.h>
DateTime myDT;
uint32_t arbitraryInteger = 42;

void setup() {
  myDT = arbitraryInteger;
  // ...moreover, to make it perfectly clear...
  myDT = 42;
}

Meaningless date and time values wwere retrieved from the DateTime instance following such an assignment.

Code writers using this library should exercise care to ensure that only sensible values are assigned to a DateTime instance.

My question for the community is whether -- and how -- the DateTime class can be defined in such a way that the Arduino IDE compiler will reject assignments of values, to a DateTime instance, that are of other, different, incompatible data types.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions