473,795 Members | 2,667 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Restricted arrays

Is there a way to mimick restricted pointers
using array syntax ? So I'm looking for something
to add to a statement such as "int arr[50]" which
will tell the compiler that I will only access the contents of the
array through arr. If I was using
pointers I would do for example
int * restrict p = malloc(50 * sizeof(int))

Is there a way to do the same thing using
arrays ?
Jun 27 '08 #1
4 1464
Spiros Bousbouras <sp****@gmail.c omwrites:
Is there a way to mimick restricted pointers
using array syntax ? So I'm looking for something
to add to a statement such as "int arr[50]" which
will tell the compiler that I will only access the contents of the
array through arr. If I was using
pointers I would do for example
int * restrict p = malloc(50 * sizeof(int))

Is there a way to do the same thing using
arrays ?
I don't think so.

A possible workaround might be:

int do_not_refer_to _this[50];
int * restrict p = do_not_refer_to _this;

Of course p is not an array, so sizeof p won't give you the size of
the array as it would if you could do this directly.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #2
Spiros Bousbouras wrote:
Is there a way to mimick restricted pointers
using array syntax ? So I'm looking for something
to add to a statement such as "int arr[50]" which
will tell the compiler that I will only access the contents of the
array through arr. If I was using
pointers I would do for example
int * restrict p = malloc(50 * sizeof(int))

Is there a way to do the same thing using
arrays ?
Are you sure this is meaningful? (I can't even convince
myself that your example is meaningful, so maybe there's
something I haven't grasped ...)

If the array identifier has internal linkage (file-scope
static) or no linkage (auto or block-contained static), the
compiler can see for itself whether you aim any other pointers
at it or at its interior. If you pass a pointer to the array
to some other function the compiler pretty much has to assume
that the other function may derive further pointers from it and
maybe return those aliases to you, but usually that's *why* you
call such a function: `p = strchr(string, '\n')' is *intended*
to create another access path.

If the array identifier has external linkage, I'm pretty
much certain that `restrict' is meaningless. Formally, the
`arr' in Module 1 and the `arr' in Module 2 are different
identifiers; the process of linkage makes these two identifiers
refer to the same object. So the mere existence of one of the
pair makes it impossible for the other to be "the one and
only," and vice versa. What would `restrict' mean?

... but I must confess that my grasp of `restrict' is
somewhat, er, restricted in scope.

--
Er*********@sun .com
Jun 27 '08 #3
if use "int array[50] in local fuction" .when the program
run ,compiler allocates memory space in stack area.
if you use malloc function ,compiler acclocates memory space in heap
area.
"int array[50]" array is a constant pointer ,you can't change it.
"malloc..." you can change its direction and point somewhere.
Jun 27 '08 #4
On Wed, May 21, 2008 at 12:44:00PM -0700, Spiros Bousbouras wrote:
Is there a way to mimick restricted pointers
using array syntax ? So I'm looking for something
to add to a statement such as "int arr[50]" which
will tell the compiler that I will only access the contents of the
array through arr...
I am not quite sure if this works out, the experts will surely know...
If you declare your array as
struct { int a; } arr[50];
then the aliasing rules will restrict the access to it either through
the struct above (e.g. arr[3].a) or through a pointer to char.

Szabolcs

Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
2579
by: Sean R. Lynch | last post by:
I've been playing around with Zope's RestrictedPython, and I think I'm on the way to making the modifications necessary to create a capabilities-based restricted execution system. The idea is to strip out any part of RestrictedPython that's not necessary for doing capabilities and do all security using just capabilities. The basic idea behind capabilities is that you don't give any piece of code you don't trust a reference to something...
13
4032
by: Rolf Magnus | last post by:
Hi, I would like to embed a python interpreter within a program, but since that program would be able to automatically download scripts from the internet, I'd like to run those in a restricted environment, which basically means that I want to allow only a specific set of modules to be used by the scripts, so that it wouldn't be possible for them to remove files from the hard drive, kill processes or do other nasty stuff. Is there any...
5
2597
by: Peter Ammon | last post by:
It's my understanding that the printf() function is declared as int printf(const char * restrict format, ...); in stdio.h. And loosely speaking, if a parameter is declared as restricted, then accesses to the object must go through that parameter. Does this mean that printf("%s", "%s");
0
1106
by: Jussi | last post by:
Hi! I have a COM server object in which I have set certain interfaces restricted/hidden. For example With VB client these attributes works as excpected. However if I use this same COM component from C# client hidden/restricted attributes seems to have no effect. Is there any way to restrict C# client's access to certain
1
7762
by: Kiran_Juikar | last post by:
In my application, I want to copy some file from network location to local machine folder. It works fine for administrator but If I run it with restricted user (not having permissions to local machine folder) it gives me Access denied error. How can I programmatically give permission to the foder for restrcited user.
0
1818
by: Niklas | last post by:
Hi this is my test class which I want to use in COM: <System.Runtime.InteropServices.InterfaceType(Runtime.InteropServices.ComInterfaceType.InterfaceIsDual), _ System.Runtime.InteropServices.GuidAttribute("2cd218b0-0026-48bb-87f1-144677d45f01")> _ Public Interface ILoadAssembly Function GetValue(ByVal Value As Object) As Object Function GetValueArray(ByVal Value() As Object) As Object() End Interface
3
1418
by: Josué Maldonado | last post by:
Hello list, This is an inventory system where some users are restricted to view only certain suppliers, those restrictions are in a table called pedusers (username,supplierallowed), there are other kind of "superuser" who are not restricted, actually I created another table for them (userexcept). To select restricted rows I use this code: select * from prvdor where prvtiprov = 2 and
21
1724
by: iapain | last post by:
I'm developing a webIDE for python and I've 2 questions regarding it. 1. How can i disable some of the modules without deleting. e.g I wish to disable "os" module. 2. How can i force user code to access only his particular folder, I dont want to create uses in unix, e.g fp = open(PATH, 'w') # If this PATH is defined then use can access files else he cant .. is there is any way?
3
2642
by: Paul Rudin | last post by:
I'm occasionally seeing tracebacks like this: Traceback (most recent call last): File "logging/__init__.py", line 744, in emit File "logging/__init__.py", line 630, in format File "logging/__init__.py", line 421, in format RuntimeError: instance.__dict__ not accessible in restricted mode I'm not sure what it means. Googling leads me to <http://docs.python.org/lib/restricted.htmlbut that says that those
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10436
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.