TweetFollow Us on Twitter

Feb 95 Top 10
Volume Number:11
Issue Number:2
Column Tag:Think Top 10

Think Top 10

This monthly column, written by Symantec’s Technical Support Engineers, aims to provide you with technical information based on the use of Symantec products.

By Mark B. Baldwin and Steve Howard, Symantec Technical Support

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

Q. Why do I get bus errors when I create a CStyleText object by using the constructor with arguments?

A. In the process of upgrading the TCL, constructors with arguments were added to the classes. In this case, constructors with arguments do not create a new handle to a TERec, the macTE data member of the CStyleText object. To work around this, call the constructor with no arguments and call the IStyleTextX() method.

Q. I am having trouble using sizeof() with printf(). For example:

printf("char size is %d.", sizeof(char));

outputs "char size is 0." Why do I get the wrong result?

A. The output is wrong because the return value of the sizeof() function is a size_t (an unsigned long). Use an %ld rather than a %d as a format specifier. Thus, the correct syntax is

"printf ("The size of a char is %ld.", sizeof(char));" 

Q. How can I avoid problems deleting heap objects whose references are on the stack when using exception handling? The pointer (which is on the stack) to the object becomes invalid when the stack unwinds and only the destructors for automatic objects are guaranteed to be called when an exception is thrown.

A. To handle this, declare pointers as volatile. Last month we explained why you should use the volatile type. Below is a practical example. Use volatile file pointers so that stack unwinding does not reset the value of the pointer (prohibiting the file from being closed).

  funClass * volatile funClassPtr;    // Syntax for volatile declaration 
  funClassPtr = NULL;         // Pointer to NULL guarantees delete as safe.
  int myInt = 1;                      // Watch in debugger to see
                                      //   the stack unwind.
  try_ {
    funClassPtr = TCL_NEW(funClass, ());//macro for new operator
    myInt = 2;                          //put new value on stack
    Failure (2, 100);                   // Force exception 
  } 
  catch_all_() {                      //catch block
    
  delete funClassPtr;                 //this calls destructor.
     
     // myInt is reset to 1, delete removes the object from the  heap 
  }
  end_try_                            //end of try block

Q. How can I use exception handling without using the Think Class Library?

A. To use exception handling without the Think Class Library, include BRLib and Exceptions.cp in your project. Also, compile with the directive #define NO_TCL

The four macros used to make exception handling work correctly are:

  AUTO_DESTRUCT_OBJECT
  TCL_NEW
  TCL_END_CONSTRUCTOR
  TCL_START_DESTRUCTOR

The macro AUTO_DESTRUCT_OBJECT will guarantee that the destructor is called for an automatic object on the stack. A destructor will only work on a completely constructed object. TCL_END_CONSTRUCTOR helps the compiler to determine the complete construction of an object.

Here’s an example that shows how the macros are used.

class funClass TCL_AUTO_DESTRUCT_OBJECT //macro in class header  
{ 
public:
    funClass()  {                       // no arg constructor 
    cout<< "In constructor."<<endl;
    char * myStr = new char[64];        // allocate memory 
    TCL_END_CONSTRUCTOR                 // End of the constructor
    }
    virtual ~funClass() {               // virtual destructor 
    TCL_START_DESTRUCTOR                // Beginning of the destructor 
    cout<< "In destructor."<<endl;
    delete [] myStr;                    // deallocate memory 
    } 
};

Q. Where can I get the Quickdraw GX headers?

A. APDA has a Quickdraw GX Developer’s Kit which contains a CD with the electronic versions of Inside Macintosh for GX, headers, required system software components, and excellent examples which are compilable under THINK C or Symantec C++. For ordering information, call (800) 282-2732. [If all you need is the header files, check out the MacTech Magazine online sites. See page 2 for details - Ed stb]

Q. When I build an application with the TCL, the application does not seem to be scriptable. How can I make it scriptable?

A. The default flags for the SIZE Resource of the application are set to not receive Background NULL Events. Make sure that the flags for your application have this bit turned on.

Q. I have a program that I’m converting from DOS and would like to be able to draw some simple graphics to the console window. How can I do that?

A. Don’t do it. If you draw to the console window, you will not receive update events. However, if you just can’t help yourself from going down this path, here is how to do it.

 #include <iostream.h>
    
 WindowPtr myWindow;         // To be used for the console window.
     
 void main (void)    {    
   cout << " ";                //A simple way to show the console.
   myWindow = FrontWindow();   //Get a pointer to the console.
   SetPort(myWindow);          //Set the port for drawing.
   PenNormal();                //Set the pen for drawing.
   LineTo(100,47);             //Draw a line.     
 }

Q. If I am mixing C and C++ code, should I turn on the option to use Native Floating Point format?

A. Yes. Symantec’s C++ compiler is using the Native Floating Point format. To make sure that your floating point calculations give you the expected results, turn on Use Native Floating Point in the options for the C compiler.

Q. Will Symantec be updating the THINK Reference Databases?

A. Yes. THINK Reference is undergoing a massive overhaul. It will be updated for the Universal Headers and the Think Class Library, and will include new databases for C++ Error Messages. As before, references will be hyperlinked for easy access to information.

Special thanks to: Craig Conner, Colen Garoutte-Carson, Rick Hartmann, Michael Hopkins, Scott Morison, Celso Barriga, Kevin Irlen, Yuen Li, and Chris Prinos.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Pinegrow 6.23 - Mockup and design web pa...
Pinegrow (was Pinegrow Web Designer) is desktop app that lets you mockup and design webpages faster with multi-page editing, CSS and LESS styling, and smart components for Bootstrap, Foundation,... Read more
WhatsApp 2.2149.4 - Desktop client for W...
WhatsApp is the desktop client for WhatsApp Messenger, a cross-platform mobile messaging app which allows you to exchange messages without having to pay for SMS. WhatsApp Messenger is available for... Read more
Microsoft Remote Desktop 10.7.4 - Connec...
Microsoft Remote Desktop for Mac is an application that allows connecting to virtual apps or another PC remotely. Discover the power of Windows with Remote Desktop designed to help you manage your... Read more
ffWorks 2.6.7 - Convert multimedia files...
ffWorks, focused on simplicity, brings a fresh approach to the use of FFmpeg, allowing you to create ultra-high-quality movies without the need to write a single line of code on the command-line.... Read more
Opera 82.0.4227.58 - High-performance We...
Opera is a fast and secure browser trusted by millions of users. With the intuitive interface, Speed Dial and visual bookmarks for organizing favorite sites, news feature with fresh, relevant content... Read more
Day One 6.15 - Maintain a daily journal.
Day One is an easy, great-looking way to use a journal / diary / text-logging application. Day One is well designed and extremely focused to encourage you to write more through quick Menu Bar entry,... Read more
Default Folder X 5.6.3 - Enhances Open a...
Default Folder X attaches a toolbar to the right side of the Open and Save dialogs in any OS X-native application. The toolbar gives you fast access to various folders and commands. You just click on... Read more
OmniOutliner Pro 5.9.2 - Pro version of...
OmniOutliner Pro is a flexible program for creating, collecting, and organizing information. Give your creativity a kick start by using an application that's actually designed to help you think. It's... Read more
OmniOutliner Essentials 5.9.2 - Organize...
OmniOutliner Essentials (was OmniOutliner) is a flexible program for creating, collecting, and organizing information. Give your creativity a kick start by using an application that's actually... Read more
QuickBooks 19.0.11.984 - Financial manag...
QuickBooks helps you manage your business easily and efficiently. Organize your finances all in one place, track money going in and out of your business, and spot areas where you can save. Built for... Read more

Latest Forum Discussions

See All

The Best Wordle Clone in Town – The Touc...
In this week’s episode of The TouchArcade Show we dig into the drama of the moment which is the cloning and subsequent gloating about the cloning of the lovely little free word game Wordle. This leads into some additional drama about how PUGB Mobile... | Read more »
TouchArcade Game of the Week: ‘Cards Inf...
There’s nothing I love more than a perfect mobile game. What do I mean by that? Well, no game is actually perfect, but there’s something special about a game you know you can just whip out at a moment’s notice and dive into, and you know it will... | Read more »
‘Micro RPG’ Bringing Streamlined RPG Goo...
Originally announced on our forums more than 3 years ago, Micro RPG is an upcoming mobile game from a two-person studio that goes by the name JoliYeti Games and, as the title implies, it looks to offer all the fun of an RPG but in a more condensed... | Read more »
SwitchArcade Round-Up: ‘Kensei: The Seco...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for January 14th, 2022. Yesterday was a big day, but today shows that we’re still warming up the engines for this year. There are a handful of new releases, but nothing nearly as... | Read more »
Mobile MMORPG Shooter ‘Avatar: Reckoning...
Archosaur Games, Tencent, Lightstorm Entertainment, and Disney have just revealed a mobile MMORPG shooter Avatar: Reckoning. Avatar: Reckoning will be published by Level Infinite when it hits iOS and Android. It is an official Avatar game developed... | Read more »
‘Crashlands+’ Is Out Now on Apple Arcade...
The brilliant Crashlands from Butterscotch Shenanigans was confirmed to arrive on Apple Arcade as an App Store Great in the form of Crashlands+ () a little while ago and it has just released worldwide. If it isn’t live yet, it should roll out in... | Read more »
SwitchArcade Round-Up: ‘Eschatos’, ‘To B...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for January 13th, 2022. It’s a Thursday, and we’ve got a pretty hefty bag of new releases to dig into. There are always some fun surprises, and this week that came in the form of SNK Vs... | Read more »
‘Crush the Castle Legacy Collection’ Lau...
Ever since Angry Birds broke into the mainstream and became a household name more than a decade ago, there’s always been a small niche of people on the sidelines who would pipe up to remind everybody that “Crush the Castle did it first!" Indeed, the... | Read more »
Non-Violent Stealth Game ‘El Hijo – A Wi...
Over a year ago, Handy Games brought the non-violent stealth game El Hijo – A Wild West Tale to Switch, PS4, Xbox, PC, and Stadia. El Hijo – A Wild West Tale has been developed by Honig Studios and Quantumfrog. You play as El Hijo, a six year old,... | Read more »
‘ZED BLADE’ from SNK and Hamster Is Out...
After a bit of a break likely due to the holiday season, we’ve gotten a new title in the ACA NeoGeo series on iOS and Android. SNK and Hamster originally brought the series to mobile with Samurai Shodown IV, Alpha Mission II, and Metal Slug 5.... | Read more »

Price Scanner via MacPrices.net

Get an Apple Watch Series 7 for $50 off MSRP,...
Amazon has Apple Watch Series 7 models on sale for $50 off MSRP including free shipping. Their prices are the lowest available for Apple Watch Series 7 models today: – 41mm Apple Watch Series 7 GPS... Read more
Here are the details of Apple’s 2022 Educatio...
Need a new Apple Mac or iPad for school? Whether you’re a student, teacher, or staff member, you can use your .edu email address when ordering at Apple Education to take up to $400 off the price of a... Read more
Amazon is blowing out 2020 21″ iMacs for only...
Amazon has clearance 2020 21″ iMacs (2.3GHz Dual-Core i5, 8GB RAM, 256GB SSD) on sale right now for $599.99 including free shipping. Original MSRP for this model was $1099. Amazon expects delivery in... Read more
Find the best deal on an Apple MacBook using...
In the market for a new 13″ MacBook Air, 13″ MacBook Pro, 14″ MacBook Pro, or 16″ MacBook Pro with M1, M1 Pro, or M1 Max Apple Silicon? Use our Apple award-winning and exclusive price trackers to... Read more
Red Pocket Mobile is offering the Apple iPhon...
Switch to Red Pocket Mobile and get an Apple iPhone 13 Pro for $50 off MSRP, plus get free 6 months of Unlimited nationwide 5G service with the purchase of any iPhone 13. Red Pocket Mobile is a... Read more
24″ M1 iMacs on sale for $1249, $50 off Apple...
Amazon has base 24″ M1 iMacs (8-Core CPU/7-Core GPU/8GB RAM/256GB SSD) on sale today for $1249 shipped. Their price is $50 off Apple’s MSRP, and it’s the lowest price available for a new 24″ M1 iMac... Read more
Open-Box 16″ M1 Pro MacBook Pros available fo...
QuickShip Electronics has open-box return 16″ M1 Pro MacBook Pros in stock and on sale for $200-$300 off MSRP on their eBay store right now with free express delivery. According to QuickShip, “The... Read more
Stock Alert! Order a new 16″ M1 Pro MacBook P...
New 16″ MacBook Pros with Apple’s M1 Pro and M1 Max CPUs have been very hard to find, largely due to current global supply constraints. However, B&H Photo is reporting stock of Space Gray... Read more
Apple has maxed-out 13″ M1 MacBook Airs (16GB...
Save $250 on maxed-out 13″ M1 MacBook Airs today at Apple (16GB RAM/1TB SSD) with Certified Refurbished models available for $1399 in Space Gray and Gold colors. Regular price for this configuration... Read more
New promo at Xfinity Mobile: $400 off any App...
Xfinity Mobile is offering any new Apple iPhone for $400 off MSRP for new customers. This includes the iPhone 13. Price for the phone, including the discount, is spread monthly over a 24 month term... Read more

Jobs Board

Registered Nurse (RN) Employee Health PSJH -...
…is calling for a Registered Nurse (RN) Employee Health PSJH to our location in Apple Valley, CA.** We are seeking a Registered Nurse (RN) Employee Health PSJH to be Read more
Systems Administrator - Pearson (United State...
…and troubleshoot Windows operating systems (workstation and server), laptop computers, Apple iPads, Chromebooks and printers** + **Administer and troubleshoot all Read more
IT Assistant Level 1- IT Desktop Support Anal...
…providing tier-1 or better IT help desk support in a large Windows and Apple environment * Experience using IT Service Desk Management Software * Knowledge of IT Read more
Human Resources Business Partner PSJH - Provi...
…**is calling a** **Human Resources Business Partner, PSJH** **to our location in Apple Valley, CA.** **Applicants that meet qualifications will receive a text with Read more
Manager Community Health Investment Programs...
…is calling a Manager Community Health Investment Programs PSJH to our location in Apple Valley, CA.** **Qualified candidates will be invited to do a self-paced video Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.