C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-24-2009, 01:26 AM   #1
Registered User
 
Join Date: Jul 2009
Location: Kerala, India
Posts: 3
Thumbs up Program on typedef - work around

Hi,

Kindly see the snippet below

Code:
typedef int *ptr;
const ptr p;
In this p is constant and not the value pointed to by p;

Suppose if we want to make the value pointed to by p, a constant, what is to be done?

Regards,
thelink123

Last edited by thelink123; 07-24-2009 at 01:29 AM. Reason: Not the explantion, but the work around that is required
thelink123 is offline   Reply With Quote
Old 07-24-2009, 01:37 AM   #2
cwr
Registered Luser
 
cwr's Avatar
 
Join Date: Jul 2005
Location: Singapore
Posts: 867
I believe your only choice is to change the typedef or create a new typedef or not use it:
Code:
typedef const int *ptr;
ptr p;
cwr is offline   Reply With Quote
Old 07-24-2009, 02:29 AM   #3
Registered User
 
Join Date: Jul 2009
Location: Kerala, India
Posts: 3
Thanks cwr
thelink123 is offline   Reply With Quote
Old 07-24-2009, 03:56 AM   #4
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
It is best not to use pointers with typedefs because they generally cause confusion. Typedef the actual type, but not the pointer part of the type.
Like
typedef int myint;
const myint* p;
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Reply

Tags
const, typedef

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Releasing a program - what is needed? A few Q's ulillillia Tech Board 9 04-28-2007 12:18 AM
placing a clear or cls command at beginning of this program help needed Mshock C Programming 15 05-13-2006 09:28 PM
Program closes prematurely. Help needed strategicman C++ Programming 3 04-12-2006 03:09 PM
Please STICKY this- vital to MSVC 6 dev - BASETSD.h Bubba Game Programming 11 03-15-2005 09:22 AM
Bug favour needed re: C++ Program Nicole C++ Programming 2 12-05-2001 07:13 AM


All times are GMT -6. The time now is 01:49 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22