Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Ivor Horton's Beginning Visual C++ 2010
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2010 by Ivor Horton; ISBN: 9780470500880
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2010 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 24th, 2012, 10:48 PM
Registered User
Points: 27, Level: 1
Points: 27, Level: 1 Points: 27, Level: 1 Points: 27, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Question Book pg 56 - char vs. signed char

Quote:
The range of values that can be stored in a variable of type char is from -128 to 127, which is the same as the range of values you can store in a variable of type signed char . In spite of this, type char and type signed char are different types, so you should not make the mistake of assuming they are the same.
I don't understand this statement. A char and a signed char are different types? I guess I thought they were the same and "signed" was optional.
  #2 (permalink)  
Old June 5th, 2012, 02:54 AM
Authorized User
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 66
Thanks: 0
Thanked 4 Times in 4 Posts
Default

kkinderen,

Maybe my reply will encourage someone else with a deeper understanding to join in. I will share my understanding with you and see if it helps. I warn you up front that I am a beginner, but I have two things going for me. I have a pretty good logical mindset, and I have played a little bit with ASCII characters with decimal conversions.

My initial explanation my seem a little unclear. If you read the entire explanation and look at the web page I link at the end, the entire subject may become more clear.

So here goes ... The Character Data Types section which contains your excerpted quote deals with different methods to deal with characters: as a character or the decimal equivalent of the ASCII character. The opening sentence of this section declares that char data type has a dual purpose and is a one byte variable.

The paragraph before your quoted passage and the paragraph you quoted from indicate that Visual C++ uses the range of -128 to 127 (signed). Remember that the value zero is included as well as the sign (+ or -). This is decided by the compiler.

One byte by definition is eight bits: 10000000(binary). This is one byte. With signed integers the leftmost bit is used for the sign (1=negative and 0=positive). My page numbers are not the same as yours; so look ahead to the section on The Bitwise Shift Operators for complete explanations which I used to provide the info above.

OK... let's go one step further. 127 (decimal)= 01111111 (binary). Because the leftmost bit is zero, this is a positive number. Remember that computers start counting at zero, not at one as you and I do. This means that the list of non-negative integer numbers contain 128 integers (0-127).

Now take a look at an ASCII table. Go ahead and click the link in the previous sentence. If you examine the tables in the linked web page, you will find that you will probably limit your use of characters to the first table, which is 0-127 decimal equivalents. Hex and octal values are included also. Binary is excluded to conserve space. The remaining characters shown in the second table (Extended ASCII Codes) are ones you probably will not use. Therefore, the 0-127 decimal ASCII equivalents chosen by the compiler should not limit you very much.To use the extended character list you must use key combinations. Look in your computer under all programs>accessories>system tools>character map if you want to use some of the characters outside of programming code.

I hope this did not get too long, but the explanation would not have explained thoroughly the significance of signed and unsigned as applied to characters and why it does not matter whether the value is signed or unsigned for our uses in learning to write code. ... at least at this stage of the learning process.

drpepper
  #3 (permalink)  
Old June 5th, 2012, 07:10 AM
Registered User
Points: 27, Level: 1
Points: 27, Level: 1 Points: 27, Level: 1 Points: 27, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

drpepper

Thanks much for the explanation. Very informative. I'm not sure it actually addressed the question but it gave me some things to think about.

The paragraph I quoted compares char to unsigned char. It says

char -128 to 127
which is the same range of values for signed char so:

char -128 to 127
signed char -128 to 127

Then it says "In spite of this, type char and type signed char are different types, so you should not make the mistake of assuming they are the same."

I read some place else that it is not defined whether char is treated as signed or unsigned and if that's the case then I understand there is a difference - but that is not how it is written here. For all I know the other reference I saw was for a different version of C++.

So I'm just a little confused by the statement char and signed char are different. In practice this probably doesn't make much of a difference I guess - I just got hung up on it.
  #4 (permalink)  
Old June 5th, 2012, 11:56 AM
Authorized User
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 66
Thanks: 0
Thanked 4 Times in 4 Posts
Default

kkinderen,

Let's see if I can make this a little more clear for you. First, you and I obviously have different editions of the same book because I am not finding the same page number and wording as you quote. Mine is ISBN: 978-0-4770-50088-0, copyright 2010. I will take your question, your quoted passage, and the wording in my book combined to try to paint the picture for you. The key concept as I read it is that for our purposes the difference is moot. For program developers the concept is essential to provide portable programs.

The visual C++ compiler uses signed (-128 to 127). This is the compiler used by this book. Other compilers like Borland, MinGW. etc. are programmed to use their own definition of char. It may be either signed or unsigned, dependent upon the compiler used. Thinking back to Chapter 1 of the book, there are different types of applications like native C++, CLR, etc. They have different structures for code and capabilities. Periodically there are explanations of the differences.

Returning to your question and the applicable excerpts as written in my book, I will paraphrase in my own words. The difference is important if you port your code to a different environment. If my understanding is correct, the ability to use code written using your computer or mine on a different computer is dependent upon several factors. What Operating System is used? What are the hardware specs? I am sure you have seen system requirements when downloading and installing various programs. All these specs must be compatible for the program to run as intended by the developer.

There is something that is a little less obvious unless you have spent some time researching C++. The version we are using for the book examples and exercises is Visual C++, not native C++. Visual C++ is developed and owned by Microsoft. Native C++ is governed by ISO specs. This gets complicated at my level of understanding. If you are as curious by nature as I am, reread Chapter 1, and research the details which are unclear. It really is not necessary to know about all of this unless your end goal is to become a program developer.

To provide you with a visual example of what I am talking about, go to Add or Remove Programs in Control Panel. Scroll through the list of programs. I would be very surprised if you do not find at least one listing for some version of Microsoft Visual C++ <some year> redistributable .... These are part of the program installation for programs compiled by the Visual C++ compiler. The developers use this to provide compatibility with various Operating Systems and combinations of hardware specs.

This prevents the necessity to write different versions of the same program for each platform where it is to be used. It would be a very time consuming task for the simple programs we write. The complex programs like Microsoft Office suite or interactive games would be prohibitive because there are literally millions of lines of code in these types of programs.

I am at the limits of my understanding at this point. I hope I have addressed your questions and comments. Anything beyond what I have presented to you begs for someone with advanced knowledge and experience to expand upon.

drpepper
  #5 (permalink)  
Old June 19th, 2012, 03:48 AM
Authorized User
Points: 45, Level: 1
Points: 45, Level: 1 Points: 45, Level: 1 Points: 45, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2012
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To: drpepper,

Good morning,

I am new to Visual C++ 2010 and new to this Forum. I have a long background of programming starting years ago with a Commodore 64, a remarkable machine. We had to program very “lean” with only 29 K of RAM! And the Commodore’s Ascii was different of the ‘normal’ Ascii so we had to have a look-up table.
I am interfacing a computer to outside devices through the parallel port. Only old computers have a parallel port and thus, I have to use W95 machines and GW Basic! Modern computers no longer have parallel ports, therefore the interfacing has now to be done through the USB port. The only interfaces available require more modern languages, one of them being C++.

One the first things I did, was to read all the postings on this Forum especially your answers and very interesting comments.

You quote the ISBN of your own book being:

978-0-4770-50088-0, copyright 2010, mine is:
978-0-470-50088-0, copyright 2010. (with only one “7”).

Do we have the same book? I hope so, as having followed your postings on the Forum, I am sure I have a lot to learn by following them.

Best regards
  #6 (permalink)  
Old June 19th, 2012, 10:47 AM
Authorized User
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 66
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Hi com64,

Yes, we have the same book. The extra 7 was a mistake. There is one more reminder that spell check is not is not the do all - save all!!

My programming background is very trivial at best; so I am attacking the book very slowly in an attempt to fully grasp every concept provided. A side trip into a study of two's complement is an example. To make my learning experience a little more challenging, this is independent study. I have no teacher or mentor to help me along the path.

Having someone with your programming background provide positive feedback on my posts is humbling. Thank you very much. Please feel free to correct me in the various posts where I may have been wrong in my analyses of the topics in question. It will go a long way toward increasing my understanding.

I am providing a brief resume of my computer experience here so you can understand where your explanations may be helpful to me. I remember when Atari and Commodore were new, exciting technologies. I had hands-on experience with IBM 360 using Fortran IV and a little Assembly for one year in high school (key punch cards, 80-80 line printer stuff) in the 1969-1970 school year. In the 1980s I had the opportunity to play with an 8086 machine for about six weeks. I taught myself a little DOS 2.0(?) and BASIC.

In the interim years from 1970 and leading up to January, 2010, my computer exposure was limited to point of sale and time clock usage. January, 2010 began my experience of substance. I had no idea what email and folders were. I began passionately exploring everything computer related on a need to know basis. Consequently I have gaping holes in my knowledge base. My quest is to fill those holes.

This is the context behind my posts, both as questions and replies. I believe that you will soon pass me up in the progress through the book because of the knowledge and experience you bring with you. Hopefully we can learn from each other.

Thank you once more for your encouraging words. Let's keep the dialog going.

regard,
drpepper
  #7 (permalink)  
Old June 20th, 2012, 09:32 AM
Authorized User
Points: 45, Level: 1
Points: 45, Level: 1 Points: 45, Level: 1 Points: 45, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2012
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear drpepper,

Thank you for your nice reply.

‘Old memories’ come back while reading your previous experience. I now remember writing an automatic mail box for the C64 with a radio amateur transceiver. The Basic of the C64 was so slow, I had to program in Assembler. Lucky to find a very good assembler-compiler. That was Amtor and when the system changed to Pactor, I also graduated to a ‘186’, rewriting the program also in assembler. That was not successful and I gave up and used a commercial program.

Amazing what you said about your computer exposure. I remember in 1996 after landing at Christmas Island in the Pcific Ocean (now called Kiribati) and meeting a bunch of tourists. We exchange addresses and they all had an ‘email addresses’. I had no idea of what that was…

Now I run several Internet Sites written in HTML and PHP. And I had big problem learning MYSQL on my own to create a database on one of the sites. As you say, this type of learning leaves big holes.

I think with a sophisticated language like C++ there are really 2 things to grasp. The main is the principle or what I would call the ‘doctrine’ of the language, so different of the ‘spaghetti programming’ we could afford to do in simpler languages like Basic. The second, of course is the syntaxe of the language, but this is almost easier. One has just to learn by practising. That is why I am still in the first chapter of the book, trying to understand the Windows environment. I appreciated the box on page 26. In all my previous attempts, the black console would flash and disappear…

I understand you are miles ahead of me in C++ and I am looking forward at following your posts.

Best regards

C64
  #8 (permalink)  
Old June 20th, 2012, 11:09 AM
Authorized User
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 66
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Good morning C64,

You bring a big advantage to the table. Your multiple programming language experience is very likely to make it easier for you to to absorb the style of this book. We are going to be using both command line and windows programming. Likewise the somewhat parallel study of different variations of C++ may be easier for you to absorb. I find myself constantly thumbing through my notes and previous pages of the book in an effort to determine the syntax and structural differences between native C++ and C++/CLI when working through the solutions at the end of the chapter. I am quite sure that I will experience the same when moving into the windows applications. Unfortunately I can neither justify nor afford the paid version of Visual C++; therefore, I am going to have to find an alternative to MFC.

I believe you may find the solution downloads helpful from time to time. I can guide you to them if you wish. That would probably benefit others reading within this forum if a new thread is opened for the topic. I have instant notification selected for this entire forum.

Since you are still in Chapter 1, I believe you will benefit from a little experimentation. I have found it enlightening to open projects (without any code of your own) in each format given by the book and then expanding upon them. Try expanding all the entries found in the solution explorer (left pane) and clicking on all results. Create different options. For example with or without precompiled headers, empty (or not) projects, different property options, etc. I have printed the results found in the text editor for examination and reference.

I completed an Introduction to Programming college course in May. It was mainly a concepts course which began with programming in Alice and wrapped up with about four weeks of C. We used Visual C++ Express once we "graduated" to the C (not C++) programming language. I took three things from this class with me to this book. The first, provided by the professor, is to use expert settings. The other two I came up with on my own. I have downloaded the help files to my computer. (I hate leaving an offline task to find myself toggling between the task and the Internet.) I have found extensive compiler, linker, and other error entries in help. The other is the ability to print line numbers along with the code when producing a hard copy of solutions. I find this very helpful when making notes for reference. I can provide details if you wish.

Regarding your experience with the book to date and observations about C++, here is what I have found. The Console::ReadLine() function is very helpful in C++/CLI. It only took one experience in running a program to tattoo that in my memory.

I am thinking that what you are calling the doctrine of the language includes the basics of pointers (one of the fundamentals of C), strongly typed, and object oriented vs. procedural programming. These concepts are foreign to the mindset I have developed over the years. Until I become comfortable with them, they present a stumbling block for me. Quite a bit of research has helped make these topics more clear. As you said, practice is the key.

There are two books I own which may be helpful to you for database design and manipulation. They are a little beyond me at present, but your experience may provide the necessary foundation for creating or modifying databases. The books are Database Design for Mere Mortals (ISBN-13: 978-0-201-75284-7) and SQL Queries for Mere Mortals (ISBN-13: 978-0-321-44443-1). My take on the books is that an understanding of the object oriented concept is the foundation of effective, useful database design and manipulation. That is one of several reasons I am studying C++ now.

I hope this has not been too verbose.

regards,
dp
  #9 (permalink)  
Old June 22nd, 2012, 08:50 AM
Authorized User
Points: 45, Level: 1
Points: 45, Level: 1 Points: 45, Level: 1 Points: 45, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2012
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello drpepper,

Thank you for the reference of these 2 books. I did not know them. My best book on MySQl is still “PHP and MySQL” from O’Reilly, ISBN 0-596-00543-1. Very thick both in size and contains. Not a book for beginners, it took me a while to be able to use it. My real problem at the time was not really how to set up and manage a relational DB but to publish it on the Internet. Most books, at the end of the last chapter have a short paragraph saying: ”Now that your DB is up and running if you want to publish it on the Net, consult a IT specialist”…Not very useful. I had to find myself out how to write the PHP pages that can access and manage the DB. Very interesting but time consuming when one has to reinvent the wheel.

Going back to C++, I discovered (you probably have too) 3 pages of Errata for the book. Here is the URL:
http://www.wrox.com/WileyCDA/WroxTit...Cd-ERRATA.html

Best regards

Com64
  #10 (permalink)  
Old June 22nd, 2012, 10:46 AM
Authorized User
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 66
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Thanks com64,

The reminder about the errata should prove to be helpful. I really need to adjust my habits. If I don't constantly remind myself to consult errata and print it if convenient, it becomes out of sight - out of mind. I have my hard copy now thanks to your reminder to consult the (should be) obvious resource.

Are you using the paid version of Visual Studio? If so, from time to time our dialogs may not address the same features and capabilities. I have already encountered explanations of a few limitations of the Express version I am using.

regards,
drpepper




Similar Threads
Thread Thread Starter Forum Replies Last Post
Strings (differences between an array of char and *char) gabberfrombcn C++ Programming 2 August 30th, 2010 08:02 PM
Big challenge here! How to convert char* to char^? samiswt Visual C++ 2005 1 November 30th, 2007 09:09 PM
Access 2003 VBA PG 55-56 KellyR Access VBA 3 June 9th, 2007 08:32 AM
Invalid conversion from 'char*' to 'char' deuxmio C++ Programming 3 December 8th, 2006 07:56 AM
Escape char for '-' mattastic Access 1 October 6th, 2005 03:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.