473,836 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why multiplication not allowed?

Hi,

Why multiplication of pointers is not allowed?
Till now I only know this, but not the reason why!

PS: As a rule, I searched the FAQ, but could not
find an answer.

--
Vijay Kumar R Zanvar
My Home Page - http://www.geocities.com/vijoeyz/
Nov 14 '05
87 11257
"Dik T. Winter" <Di********@cwi .nl> writes:
In article <ln************ @nuthaus.mib.or g> Keith Thompson <ks***@mib.or g> writes:
> "Dik T. Winter" <Di********@cwi .nl> writes: [...]
> > None at all. There is *no* hardware support for 8 bit quantities. >
> Thanks, that's an interesting thing to know. I tried looking at an
> assembly listing to figure out how the operations are implemented, but
> Cray's assembler syntax is a bit odd, and I've never taken the time to
> learn it.


I never thought Cray assembler a bit odd. I have programmed quite a bit
in it. It reminds one of the assembler for the CDC 7600. Not so much of
a surprise.


Well, it's odd compared to the assembler syntaxes I'm familiar with.

[...]
> But porting gcc to Cray vector machines, even without
> vector support, apparently is more work than anyone has been willing
> to do. (Since I'm not willing or able to do the work myself, I'm
> certainly not criticizing anyone else for not doing it.)


Porting any untility to the Cray is much work. I have helped somebody
port a derivate of the Bourne shell to the Cray. I have ported the
Korn shell to it. Not entirely simple. The main reason being that
they assumed non-portable things (like being able to use the low
order bit of an int pointer as a flag).


It depends on the utility, I suppose. I've recompiled quite a few
things on Crays without too much difficulty, but probably quite a few
of them had already been ported (sometimes with masses of #ifdefs).

One example: as far as I know, Perl compiles out of the box.

[...] I think the software would have broken just as much. I understand the
Unix port has been a nearly complete rewrite of almost all utilities.


Hmm, that's surprising.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 14 '05 #71
Arthur J. O'Dwyer wrote:
On Thu, 8 Jan 2004, glen herrmannsfeldt wrote:
How about a C for loop such as:

char s[100];
for(strcpy(s, "1"); strcmp(s,"100") <0; sprintf(s,"%3d" ,atoi(s)+1)) ;

assert(0 == strcmp(s, "2"));

[Whoops.]


I presume you didn't run the loop, though you don't say the
results of the assert.

The "%3d" is important to make it work, along with a character
set where ' ' < '1'.

-- glen

Nov 14 '05 #72

On Fri, 9 Jan 2004, glen herrmannsfeldt wrote:

Arthur J. O'Dwyer wrote:
On Thu, 8 Jan 2004, glen herrmannsfeldt wrote:
char s[100];
for(strcpy(s, "1"); strcmp(s,"100") <0; sprintf(s,"%3d" ,atoi(s)+1)) ;


assert(0 == strcmp(s, "2"));

[Whoops.]


I presume you didn't run the loop, though you don't say the
results of the assert.

The "%3d" is important to make it work, along with a character
set where ' ' < '1'.


Hmm... if it weren't for that last assumption, I'd have to say
"move that Whoops down two levels of quotation." :( But you could
actually fix the code, couldn't you, by changing "%3d" to "%03d".
Then it would work no matter what value your system gave to ' '!

atoi("010") == 10, right? What standard functions treat "010"
as octal? Could someone with a fast connection and 'grep' please
give a list of those circumstances? (I think there's some 'scanf'
format that understands 0x and 0, isn't there?)

-Arthur
Nov 14 '05 #73
Arthur J. O'Dwyer wrote:

atoi("010") == 10, right? What standard functions treat "010"
as octal? Could someone with a fast connection and 'grep' please
give a list of those circumstances? (I think there's some 'scanf'
format that understands 0x and 0, isn't there?)


%i does for scanf. The various strto* functions can also, if you give
them a base of 0.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Nov 14 '05 #74
Kevin Goodsell wrote:
Arthur J. O'Dwyer wrote:

atoi("010") == 10, right? What standard functions treat "010"
as octal? Could someone with a fast connection and 'grep' please
give a list of those circumstances? (I think there's some 'scanf'
format that understands 0x and 0, isn't there?)

%i does for scanf. The various strto* functions can also, if you give
them a base of 0.


Also: atoi always uses base 10 (as if calling strtol() with 10 as the
base argument), so your first statement is correct.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Nov 14 '05 #75
In article <ln************ @nuthaus.mib.or g> Keith Thompson <ks***@mib.or g> writes:
"Dik T. Winter" <Di********@cwi .nl> writes:
In article <ln************ @nuthaus.mib.or g> Keith Thompson <ks***@mib.or g> writes: ....
> Cray's assembler syntax is a bit odd, and I've never taken the time to
> learn it.
I never thought Cray assembler a bit odd. I have programmed quite a bit
in it. It reminds one of the assembler for the CDC 7600. Not so much of
a surprise.


Well, it's odd compared to the assembler syntaxes I'm familiar with.


Ah, I know stranger syntaxes than Cray's. Here a short routine that sets
the register at 1 when the current value >= +0 and to -1 when it is <= 0:
F = F, P
Y, F = 1
N, F = -1
The keyword syntax as you know it is one of the many syntaxes around.
Porting any untility to the Cray is much work. I have helped somebody
port a derivate of the Bourne shell to the Cray. I have ported the
Korn shell to it. Not entirely simple. The main reason being that
they assumed non-portable things (like being able to use the low
order bit of an int pointer as a flag).


It depends on the utility, I suppose. I've recompiled quite a few
things on Crays without too much difficulty, but probably quite a few
of them had already been ported (sometimes with masses of #ifdefs).


It also depends on the time-span. When Cray started developing Unicos
(early 1990's I think), there was not yet really much consideration for
portability in the source of utilities. Especially to machines that
were not Vax lookalikes.

One example: as far as I know, Perl compiles out of the box.


Probably. Currently utilities are much better programmed. But I know
that (for instance) wuftpd will not work out of the box on a machine
where the bit pattern of the null pointer is not all zero bits and
NULL is defined as (void *)NULL. However, currently there are still
utilities that assume that if you cast a pointer to char to a pointer
to int and back again to a pointer to char, this may fail (and not
only on the Cray, but with the C compiler I used on the Cray it would
certainly fail). And there is still software around that makes this
assumption. (Of course it would also fail on a DG MV.) On the other
hand, compiling out of the box does *not* mean that it will work.
I think the software would have broken just as much. I understand the
Unix port has been a nearly complete rewrite of almost all utilities.


Hmm, that's surprising.


Not so very much. When Unicos was started, portability of source in C
was still in its infancy. Take the source for the Bourne shell for
instance. It would compile out of the box, but it would not work at
all (its memory allocation and deallocation routines would fail amongst
other problems %). There were too many utilities where the source assumes
something special about the machine which is false on a slightly esoteric
architectures. Getting Unix and all utilities to work on a 80286 also
has taken quite some rewriting, I understand.
(And there still are.)
-
% The Korn shell I ported to the Cray had no longer these problems, because
there were #ifdefs for the Cray in the source. I no longer have the source
available, but if I remember correctly, there were quite a few. However,
many of those #ifdefs would not have been needed if portability had been
the first concern.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Nov 14 '05 #76
Arthur J. O'Dwyer wrote:
On Fri, 9 Jan 2004, glen herrmannsfeldt wrote:
(snip of for loop using strings)
The "%3d" is important to make it work, along with a character
set where ' ' < '1'.

Hmm... if it weren't for that last assumption, I'd have to say
"move that Whoops down two levels of quotation." :( But you could
actually fix the code, couldn't you, by changing "%3d" to "%03d".
Then it would work no matter what value your system gave to ' '! atoi("010") == 10, right? What standard functions treat "010"
as octal? Could someone with a fast connection and 'grep' please
give a list of those circumstances? (I think there's some 'scanf'
format that understands 0x and 0, isn't there?)


I wasn't too worried, ' '<'1' in both ASCII and EBCDIC.

Anyway, with the right number of blanks, you can do this with
a PL/I DO statement.

DCL S CHAR(100) VARYING;
DO S='1' TO ' 100' BY '1';
PUT SKIP LIST(SQRT(S));
END;

-- glen

Nov 14 '05 #77
"Keith Thompson" <ks***@mib.or g> wrote:
Not many years ago, I used a compiler (VAXC, I think) that allowed the
old =+ syntax, but I think it at least issued a warning about it.


We still use one at my work. There used to be a lot of places in the code
that looked like this:

something =NULL;
other =NULL;
whatever =&something_els e;

Please note lots of spaces before '=' but none after it. It was the
prefered style of the programmer who wrote it. After the warnings, she
corrected ti to:

something =NULL;
other =NULL;
whatever =(&something_el se);

;-)
Nov 14 '05 #78
"glen herrmannsfeldt" <ga*@ugcs.calte ch.edu> wrote:
I have used compilers that allowed them for compatibility. I still
always put a space between = and -, like i= -1; to be sure.


I always use spaces around *all* binary (or ternary) operators.
For clarity.

So,
i = -1;
a = m * n + 4;
etc.

But I appreciate that it's just a matter of style.

Peter
Nov 14 '05 #79
"Eric Sosman" <Er*********@su n.com> wrote:
Vijay Kumar R Zanvar wrote:
Why multiplication of pointers is not allowed?
Till now I only know this, but not the reason why!

PS: As a rule, I searched the FAQ, but could not
find an answer.
The result would be meaningless. An easy (but
informal) way to understand this is to use an analogy:
think of pointer values as street addresses. Then
the following operations make sense:


<big snip (good examples BTW)>
- Similarly, computing "123 Main Street times
89 El Camino Real" makes no sense. Perhaps the
result might be considered a kind of "area,"
but there seems to be no useful analogous
concept to "area" in the addressing of memory-
resident objects.


No, it could not be an area. For two reasons:
1. Where is a guarante that Main Street and El Casino Real are
perpendicular? What if they are parallel? Or even in two different towns, or
even countries?
2. Even if they were perpendicular, you would need a range on each side, so
perhaps "123 to 234 Main Street times 89 to 98 El Camino Real", which boils
down to multiplication of integers ;-)

The upshot is, Ben was right.

Peter
Nov 14 '05 #80

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

Similar topics

11
2294
by: Soeren Sonnenburg | last post by:
Hi all, Just having started with python, I feel that simple array operations '*' and '+' don't do multiplication/addition but instead extend/join an array: a= >>> b= >>> a+b
9
8005
by: Ralf Hildebrandt | last post by:
Hi all! First of all: I am a C-newbie. I have noticed a "strange" behavior with the standart integer multiplication. The code is: void main(void)
11
4885
by: mjdeesh_hi | last post by:
How can we perfom multiplication programatically without using + or * operator. Can any one help out in this one. Jagadeesh.
11
5240
by: Skybuck Flying | last post by:
Hello, type Tbig = array of byte; vAddTable : array of array of byte; // = value // = transport/carry vMulTable : array of array of byte;
1
9177
by: Sozos | last post by:
Hi guys. I have a problem with writing the base case for the following matrix multiplication function I have implemented. Please help. #define index(i,j,power) (((i)<<(power))+(j)) void recMultiply(int i, int j, float a, int k, int l, float b, int x, int y, float c, int s); int i, j, k, s, matrixsize, blocksize, jj, kk, power, bsize; float sum, maxr, total=0.0, startmult, finishmult, multtime; float* A = NULL; float* B = NULL;
0
9818
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
10546
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10254
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
9371
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
7790
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...
0
6978
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5648
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4448
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
3112
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.