relative pointers on Unix


 
Thread Tools Search this Thread
Top Forums Programming relative pointers on Unix
# 1  
Old 07-07-2005
relative pointers on Unix

Hi all:
We're porting lot of C code from Windows to Unix.
In Windows we're using relative pointers (with the _based keyword) to
access some structures placed on shared memory. We would need
something like the Microsoft's _based keyword for unix.
Does something similar exist in Unix? If not, is there any other way to get the same functionality as _based on windows.

See the link below to know more about the _based keyword on windows.
http://msdn.microsoft.com/library/de...ef___based.asp

Many Thanks,
Rahul
# 2  
Old 07-07-2005
Microsoft is bad about C standards conformance.

This is a relative pointer, a pointer that is set to a base value and then offset by a fixed "distance"
Code:
int foo()
{
    int a[100]={0};     
    int *base=a;          
    int i=0;              
    for(i=0;i<100;i++)    
    {                     
         int q=*(base+i);   /* base+i is the relative pointer */
         printf("%d\n",q);
    }                     
    return 0;
}

This is also a relative pointer:
Code:
     int foo( int *a)
     {
           int i=0;
           for(i=0;i<100;i++)
           {
               printf("%d\n", a[i]); /* a[i] is also a relative pointer */
           }
           return 0;
      }

The a[i] thing is array notation, but it is an offset against a base. They are all compiled into the same machine code.
# 3  
Old 07-16-2005
Note Pad

I wrote a small C script in Note Pad and I want to know can it be executed like a shell to get results.

If not

Do I need to purchase RedHat Linus or SUSE Linus with a compliler on it for my home computer or can I get it Free.


Novice, looking for Big Help and Understandiong from you in trying to get started with writing scripts for C and C++.

Thank you in advance for your understanding of a beginner and advise.

Lost, Alone, and COnfused about C Scripts

SLP
# 4  
Old 07-24-2005
C is not a scripting language.
about your question, there're a lot of zero-price GNU/Linux distros around the www. i can suggest Gentoo which is distrubuted under the GPL, but it's installation is done by using standard unix tools (well, mostly). if you're not familiar with unix and insist on a gui-installer, you can try Fedora Core or better yet, google for GNU/Linux distros.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Relative Pathnames

Hi, Could anyone help me with the following questions about relative addressing. The questions are: 1) Enter below the command to copy the file basics.pptto the folder outline, using relative addressing. 2) Enter below to move the file .secrets.doc to the folder Day1 using relative addressing.... (1 Reply)
Discussion started by: ml123
1 Replies

2. UNIX for Dummies Questions & Answers

Help with cp command using relative path?

I have a lab I am doing for a Linux Operating class. The question I am stumped on is "For the following questions, only use the cp command to copy files. You should currently be inside your lab07 directory. Create a subdirectory inside this directory called ones and copy (working ... (1 Reply)
Discussion started by: CodyMongrel
1 Replies

3. UNIX for Dummies Questions & Answers

Teaching myself Unix - Need websites and other pointers

Hi, I am new to Unix. I've started with a book "Unix for Dummies". Please help, any websites with extensive amount of practice exercises are needed. I need to practice! Also I would appreciate any books that are good for beginners. Thanks to all! (1 Reply)
Discussion started by: zamcruiser
1 Replies

4. Shell Programming and Scripting

Pointers on writing a unix script

Hi All, I am writing a unix shell script. I have a file called Results.txt which stores 4 fields separated by pipe. i.e. a pipe delimited file. I want to loop through each record of this file and store each of these 4 fields into variables. I have read can be done through awk but I have never... (7 Replies)
Discussion started by: shwetainnani
7 Replies

5. Shell Programming and Scripting

how to read the relative path

suppose i ahve a shell script Nsdnet.sh inside a directory /dialp/Release/bin another file nsdnet_file.csv is under the same directory. Now in the shell script i have call a java file, which reads the csvfile from the commandline. Now when i run the file as $ ./Nsdnet.sh ./nsdnet_file.csv then... (5 Replies)
Discussion started by: priyanka3006
5 Replies

6. Programming

Need help with the Pointers in C

I have a special character called ô. When it is declared as a character variable its showing it can be printed. But when it is declared as a character pointer variable its showing it cannot be printed. I am just wondering why its happening like this.. c1 = '@'; c2 = 'ô'; char *fp; fp="XXô"; if... (1 Reply)
Discussion started by: sivakumar.rj
1 Replies

7. UNIX for Dummies Questions & Answers

get cygpath to leave relative paths as relative?

If I execute mypath=`cygpath -w ../` echo $mypath I get d:\unix\nextVersion\script OK, d:\unix\nextVersion\script is the correct windows version of the path, but it is in absolute form. I would prefer it if cygpath left it in relative form, i.e. echo $mypath should output ..\ ... (0 Replies)
Discussion started by: fabulous2
0 Replies

8. Programming

pointers

Hi I mash with pointers in C. I solve this problem about 5 hours and I don't know how I should continue. void InsertFirst (tList *L, int val) { tElemPtr new; if((new = malloc(sizeof(tElemPtr))) == NULL) Error(); new->data = val; new->ptr = L->frst; L->frst = new;... (2 Replies)
Discussion started by: Milla
2 Replies

9. Programming

pointers

is this a valid c declaration int (*ptr(int *b)); plz explain... (4 Replies)
Discussion started by: areef4u
4 Replies

10. UNIX for Dummies Questions & Answers

list all ports and their relative IP@ if any

Hi all i'm working on a LINUX-based platform. i'm little confused with PORTs. i have my platform connected to many other platforms, i need to know the relative port for each IP@. i know the IP of each connected platform to mine, but i'm not sure about the relative PORT for each platform...... (4 Replies)
Discussion started by: samsal_991
4 Replies
Login or Register to Ask a Question