Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7623329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:40:46+00:00 2026-05-31T04:40:46+00:00

In my previous question, I figured out that all Objective-C objects are declared as

  • 0

In my previous question, I figured out that all Objective-C objects are declared as pointers. But in C and C++, pointers can be accessed from any function, global or not, and they seem unprotected.

How are they “protected” in Objective-C ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:40:47+00:00Added an answer on May 31, 2026 at 4:40 am

    ObjC does not police your use of pointers.

    There is type checking at compile time, so if you have a pointer to an NSNumber, and use the variable that holds it to assign to an NSString, the compiler will issue a warning. However, this is easily overridden by casting the pointer, as shown below,

    NSNumber *myNumberPtr = [NSNumber initWithInt:99];
    
    NSString *myStringPtr = (NSString *) myNumberPtr;
    

    In this case, the compiler is told to keep quiet, but accessing myStringPtr as a string would cause ‘undefined results’, hopefully something obvious like a crash, but possibly something more pernicious.

    Similarly, I could declare,

    NSString *notActuallyAString = 0x897996789; // assigned some random value
    

    Then when notActuallyAString is accessed at runtime, it is highy likely to cause a bad access exception as the pointer is almost certainly not pointing to an NSString, and quite possibly isn’t a valid memory address at all.

    This makes C (and its associated languages) powerful for low-level programming (if you actually know the memory mapped address of some hardware register, you can assign them in this way, and access hardware), but brings pretty clear risks.

    It gets worse, because you may have a valid pointer at some point in the execution, but the memory that the pointer references is freed off at some later point. Then if you (wrongly) access that pointer, you again may well get an exception as the memory is no longer valid for the purpose the code assumes. Writing (assigning) a via a pointer that pointers somewhere it shouldn’t is a common cause of memory corruption, which can be a devil to diagnose. For this reason, it’s good practice (aka defensive coding) to make sure pointers that you’ve finished with are assigned to nil, so if you reuse those pointers when you shouldn’t, you should get a symptom that is more easy to diagnose than some random memory corruption.

    You need a good understanding of pointers to program in objC, and I would recommend reading the timeless classic reference book, ‘The C Programming Language’ by Kernighan & Ritchie which explains the basics of pointers, you can then build your understanding on how pointers and memory allocation is used in ObjC and C++.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From my previous question: Adding Doctype Destroys Layout I figured out that the right:-10;
Continuing from my previous question , is there a comprehensive document that lists all
This question follows on from a previous question, that has raised a further issue.
In a previous question I figured out how to start a password-authenticated ssh sessions
In previous question of mine, someone had meantioned that using Semaphores were expensive in
This question is related to a previous question of mine That's my current code
After reflecting upon all the great answers I received to my previous question about
I've got a really strange error and any light that anyone can shed on
Following on from my previous question I have been working on getting my object
This is a continuation question from a previous question I have asked I now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.