Homebrew Clarification Thread - What is going on?

  • Thread starter Thread starter JustPingo
  • Start date Start date
  • Views Views 647,812
  • Replies Replies 5,356
  • Likes Likes 103
Status
Not open for further replies.
Steveice10 just added some gotoes into his code. Just saying. (I personally don't like them)

That was exactly my point. Goto is much easier to read and maintain for cleanup then tens of nested ifelses. So calling code in c crap because it uses goto shows low experience in programming. It's not your favorite Java where you can use try finally.

Code:
int initRTC()
{
    char *buf1, *buf2;
    int ret = RTC_OK;
    if ((buf1 = (char *)malloc(20)) == NULL) {
        ret = ERR_RTC_MALLOC1;
    }
    else if ((buf2 = (char *)malloc(40)) == NULL) {
        ret = ERR_RTC_MALLOC2;
    }
    else if (openRTC()) {
        ret = ERR_RTC_OPEN;
    }
    else if (cfgRTC(buf1, 20, buf2, 40)) {
        ret = ERR_RTC_CFG;
    }
    else if (txCmd(buf1, 20, buf2, 40)) {
        ret = ERR_RTC_TX;
    }
    if (ret >= ERR_RTC_CFG) {
        closeRTC();
    }
    if (ret >= ERR_RTC_OPEN) {
        free(buf2);
    }
    if (ret >= ERR_RTC_MALLOC2) {
        free(buf1);
    }
    return ret;
}

Code:
int initRTC()
{
    char *buf1, *buf2;
    int ret = RTC_OK;
    if ((buf1 = (char *)malloc(20)) == NULL) {
        ret = ERR_RTC_MALLOC;
        goto fim0;
    }
    if ((buf2 = (char *)malloc(40)) == NULL) {
        ret = ERR_RTC_MALLOC;
        goto fim1;
    }
    if (openRTC()) {
        ret = ERR_RTC_OPEN;
        goto fim2;
    }
    if (cfgRTC(buf1, 20, buf2, 40)) {
        ret = ERR_RTC_CFG;
        goto fim3;
    }
    if (txCmd(buf1, 20, buf2, 40)) {
        ret = ERR_RTC_TX;
        goto fim3;
    }
fim3:
    closeRTC();
fim2:
    free(buf2);
fim1:
    free(buf1);
fim0:
    return ret;
}

Which one is easier to read/maintain? Now can you all please just shut-up while people that actually know any better do their job?!
 
with this new info... it's coming today guaranteed guys. unless they hold back. which they might. who knows.
 
I noticed this too. odd.
is it general ? or do they have to make a version for each fw ?
We tried on 10.1, 9.2 and 9.0.

--------------------- MERGED ---------------------------

wait, steveice10 doesn't need basical code execution on 9.3+? why he maked a 9.2- thing?
They didn't do a 9.2 thing, as it crashes on 9.2 and 9.0 too.
 
with this new info... it's coming today guaranteed guys. unless they hold back. which they might. who knows.
not garantueed. but maybe 1 or 2 or 3 days.

--------------------- MERGED ---------------------------

They didn't do a 9.2 thing, as it crashes on 9.2 and 9.0 too.
ahhhhhhhh. can it load code on 9.3+?
 
T
Code:
int initRTC()
{
    char *buf1, *buf2;
    int ret = RTC_OK;
    if ((buf1 = (char *)malloc(20)) == NULL) {
        ret = ERR_RTC_MALLOC1;
    }
    else if ((buf2 = (char *)malloc(40)) == NULL) {
        ret = ERR_RTC_MALLOC2;
    }
    else if (openRTC()) {
        ret = ERR_RTC_OPEN;
    }
    else if (cfgRTC(buf1, 20, buf2, 40)) {
        ret = ERR_RTC_CFG;
    }
    else if (txCmd(buf1, 20, buf2, 40)) {
        ret = ERR_RTC_TX;
    }
    if (ret >= ERR_RTC_CFG) {
        closeRTC();
    }
    if (ret >= ERR_RTC_OPEN) {
        free(buf2);
    }
    if (ret >= ERR_RTC_MALLOC2) {
        free(buf1);
    }
    return ret;
}

Code:
int initRTC()
{
    char *buf1, *buf2;
    int ret = RTC_OK;
    if ((buf1 = (char *)malloc(20)) == NULL) {
        ret = ERR_RTC_MALLOC;
        goto fim0;
    }
    if ((buf2 = (char *)malloc(40)) == NULL) {
        ret = ERR_RTC_MALLOC;
        goto fim1;
    }
    if (openRTC()) {
        ret = ERR_RTC_OPEN;
        goto fim2;
    }
    if (cfgRTC(buf1, 20, buf2, 40)) {
        ret = ERR_RTC_CFG;
        goto fim3;
    }
    if (txCmd(buf1, 20, buf2, 40)) {
        ret = ERR_RTC_TX;
        goto fim3;
    }
fim3:
    closeRTC();
fim2:
    free(buf2);
fim1:
    free(buf1);
fim0:
    return ret;
}

Which one is easier to read/maintain? Now can you all please just shut-up while people that actually know any better do their job?!
The code in memchunkhax is very different. Use single cleanup logic and add actions beteen validity checks and ifelse approach looses without options.
 
Status
Not open for further replies.

Site & Scene News

Popular threads in this forum