Comments (3)
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 throw
s 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.
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.
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)
- Chapter 10 file naming
- Chapter 11 file naming
- Complete Chapter 6 Calculator
- Refine the Grammar concept HOT 1
- Complete Chapter 8 Exercises
- Complete Chapter 9 Chrono HOT 2
- Complete Chapter 10 Calculator Ex
- Complete Chapter 11 Exercises
- Chap 20 Ex04 JackAndJill HOT 4
- Chapter 21 Exercise 7 HOT 2
- Chapter 23 Ex15 HOT 1
- chapter4 number guesser HOT 1
- Chapter 21 Exercise 7 Fix
- Chapter 4 file naming
- Chapter 5 file naming
- Chapter 6 file naming
- Chapter 7 file naming
- Chapter 8 file naming
- Chapter 9 file naming
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 stroustrup-ppp.