Comments (1)
I've never been able to come up with a solution that is ergonomic and reliable. It always seems to depend on the programmer to do the right thing, because the C or C++ does not provide any mechanism to bind the length information and pointer together in a robust way.
Yes the ace_time::zonedbc::kZoneAndLinkRegistry
array is known at compile-time, but the constructor actually accepts a pointer, not a compile-time array. The constructor relies on the automatic decay of the array into a pointer. It is not guaranteed that we will always know the size of the array at compile time, because the constructor of the ZoneManager
may happen in a context (e.g. inside a factory function) where we have only the pointer. We always have to rely on the programmer to pass in the correct length information as a separate parameter.
We could suggest that the programmer do something like:
ace_time::CompleteZoneManager zoneManager(
sizeof(ace_time::zonedbc::kZoneAndLinkRegistry) /
sizeof(ace_time::zonedbc::kZoneAndLinkRegistry[0]),
ace_time::zonedbc::kZoneAndLinkRegistry,
zoneProcessorCache);
This only works if the registry is a compile-time array. It does not work if it's passed in as a pointer.
This also depends on the programmer to write the correct sizeof()
expression, and that the programmer uses the correct kZoneAndLinkRegistry
array inside that sizeof()
expression. I've definitely been guilty of copy-and-pasting code like this, and forgetting to replace that array name, or length parameter. But when I write the expression from scratch, I get the sizeof()
expression wrong a substantial fraction of the time. Using a #define
macro may help, but then the programmer has to remember to either define the correct #define
macro, or remember to do a #include
of the correct header file that includes this #define
macro, which can sometimes be a source of friction.
You could say that we should create a new class (let's call it a SmartZoneRegistry
class) that binds the length and array together into a single object. But all we have done is push the problem one step back, because the code fragment that creates a new instance of the SmartZoneRegistry
is the same bit of code that creates a ZoneManager
class. The other problem with creating a new SmartZoneRegistry
class is that it seems to create too much abstraction, for not much benefit. The AceTime library already has too many classes, and I've resisted creating helper classes unless absolutely necessary.
from acetime.
Related Issues (20)
- Constructor for NtpClock::setup() missing HOT 2
- Day of week calculation is off by one HOT 2
- Need to support other WiFi platforms like the Nano 33 IOT, Maker Wifi ,etc HOT 33
- In OLED clock manual mode, can't set the clock HOT 3
- Q: AceTime with external database? HOT 5
- support megaAVR boards (e.g. Nano Every) HOT 1
- support arduino:samd Core >= 1.8.10 HOT 1
- Question: Does Acetime support standalone determination of timezone using GPS module? HOT 16
- List timezone names HOT 6
- ESP32 support HOT 2
- Broken SAMD core testing because of AceTime HOT 2
- Include order issue HOT 3
- How to handle error in lookup HOT 1
- Looking up by shortname? or TZ name? or CountryCode?
- Is AceTime working with ESP32 HOT 1
- createForZoneName no longer working for "Europe/Amsterdam" HOT 4
- gcc 11.3 compiler warning HOT 4
- Getting this error compiling for ESP32 HOT 1
- 2.3.0 compile issues HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from acetime.