473,382 Members | 1,086 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 1442
Spiros Bousbouras <sp****@gmail.comwrites:
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_Keith) 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
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...
13
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...
5
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...
0
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...
1
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...
0
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), _ ...
3
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...
21
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...
3
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.