[main.{c,h}] Let's put some safety into this code! xD

This commit is contained in:
Alexander Andreev 2022-01-06 04:23:20 +04:00
parent 1ef712c6a5
commit 8556f85781
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F
2 changed files with 7 additions and 7 deletions

View File

@ -4,7 +4,7 @@
#include "main.h"
int main(int argc, char **argv) {
int main(int const argc, const char * const * const argv) {
price_t price;
wattage_t wattage;
interval_t interval = 0;
@ -23,7 +23,7 @@ int main(int argc, char **argv) {
return 0;
}
int parse_arguments(int argc, char **argv, price_t *price, wattage_t *wattage, interval_t *interval) {
int parse_arguments(const int argc, const char *const *const argv, price_t *const price, wattage_t *const wattage, interval_t *const interval) {
if (argc < 2) return 1;
for (int i = 1, pos = 0; i < argc; ++i)
@ -46,7 +46,7 @@ int parse_arguments(int argc, char **argv, price_t *price, wattage_t *wattage, i
return 0;
}
inline interval_t interval_to_seconds(char *interval) {
inline interval_t interval_to_seconds(const char * const interval) {
interval_t intrvl = (interval_t)atol(interval);
switch (interval[strlen(interval) - 1]) {
@ -64,7 +64,7 @@ inline interval_t interval_to_seconds(char *interval) {
}
}
inline price_t to_wattspersecond(price_t price) {
inline price_t to_wattspersecond(const price_t price) {
return price / 1000.f / 3600.f;
}

View File

@ -7,10 +7,10 @@ typedef long double price_t;
typedef long double wattage_t;
typedef unsigned long interval_t;
int parse_arguments(int argc, char **argv, price_t *price, wattage_t *wattage, interval_t *interval);
int parse_arguments(const int argc, const char *const *const argv, price_t *const price, wattage_t *const wattage, interval_t *const interval);
inline interval_t interval_to_seconds(char *interval);
inline price_t to_wattspersecond(price_t price);
inline interval_t interval_to_seconds(const char * const interval);
inline price_t to_wattspersecond(const price_t price);
inline void print_version();
inline void print_usage();