Giter Site home page Giter Site logo

Comments (3)

Chrinkus avatar Chrinkus commented on July 19, 2024 1

Thanks for pointing this out! When I did these exercises I was not very knowledgeable about compiler flags and the more rigorous error checking that could be employed. I assume that when XCode compiles C programs it adds some flags that warn about this behaviour and/or treat warnings as errors and refuse to compile.

That particular function has a switch with a default case. The default case has an elaborate if chain too. Every path through has a return statement so there is no way of reaching the end of the function. If control DOES reach the end there is the error() call. This is a function that is in the std_lib_facilities.h header that bootstraps us through the first part of the text. It's got a lot going on in it but the error function can be found at line 137. It takes a string and throws the error, effectively unwinding the stack and exiting the function through a giant gaping hole in the wall.

In your own code you can add a return Token{0}; at the end of the get function and that should convince XCode.

Let me know here if it works.

from stroustrup-ppp.

acratophorux avatar acratophorux commented on July 19, 2024

Yes, using return Token{0}; does solve the problem for the time being and shuts off the Xcode error/warning; though I am not sure that returning Token{0} won’t interfere with and cause further problems when the output of get() is used in the program. But, again, as you said, there is no way of reaching the end of the function, so I guess it is sufficient for now.


Just to bring it to your notice, the same problem also lies in the Symbol_table::get_value(string s) function.

double Symbol_table::get_value(string s)    // return the value of the Variable names s
{
    for(const Variable& v : var_table)
        if(v.name == s) return v.value;
    error("get : undefined variable", s);
    //return 0;
} 

Here, returning any value other than v.value is a logical error which leaves us with no workaround.

To me, the problem seems to be attached with error() function as it does not return the type of the value to be supposedly returned by the function in which error() function is used.

from stroustrup-ppp.

Chrinkus avatar Chrinkus commented on July 19, 2024

It's the same thing. If we get that far in the function we have an error. Rather than return an error value like in C we throw an error and rely on the caller to catch it. It's unfortunate that XCode doesn't detect the throw.

from stroustrup-ppp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.