473,883 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C Pointer problem

Hi,

I can't understand why this code causes a "memory read exception" at
int x=**a;

void pass(int** a)
{
int x=**a;
}
void main()
{
int arr[2][2]={{1,2},{3,4}};
pass(arr);
}
The assignment of int int x=**a in the main function works.

Tanks for your help,
Markus

May 31 '06
73 3897
On 2006-06-26, Dave Thompson <da************ *@worldnet.att. net> wrote:
On Mon, 19 Jun 2006 11:02:31 GMT, pete <pf*****@mindsp ring.com> wrote:
Dave Thompson wrote:
>
> On 1 Jun 2006 01:26:09 GMT, Jordan Abel <ra****@random. yi.org> wrote:
>
> > 2006-05-31 <11************ *********@c74g2 000cwc.googlegr oups.com>,
> > Peter Nilsson wrote:

> > > int foo() { }

> > The standard makes a very clear distinction between empty
> > brackets in a declaration not part of a definition,
> > and empty brackets that _are_ in part of a definition.

> Where?


What?

N869
Index

( ) (parentheses punctuator), 6.7.5.3, 6.8.4, 6.8.5
[ ] (brackets punctuator), 6.7.5.2, 6.7.8
{ } (braces punctuator), 6.7.2.2, 6.7.2.3, 6.7.8, 6.8.2


Are you being dense? He obviously meant brackets in the en_GB (or UK?)
meaning, what en_US (and the standard) calls parentheses.


I know a lot of people who refer to []{}<>() as brackets (and some who
call quotes brackets), and it's much easier to just define everything
one way and act dense when others define them differently.

Sure, it was obvious that he didn't mean [] by "bracket". But what /did/
he mean? There was an empty () and an empty {} in the code.
Just my thoughts on why people don't like to talk to me. :-)

--
Andrew Poelstra < http://www.wpsoftware.net/blog >
To email me, use "apoelstra" at the above address.
I know that area of town like the back of my head.
Jun 26 '06 #31
pete wrote:

Dave Thompson wrote:

On Mon, 19 Jun 2006 11:02:31 GMT, pete <pf*****@mindsp ring.com> wrote:
Dave Thompson wrote:
>
> On 1 Jun 2006 01:26:09 GMT,
> Jordan Abel <ra****@random. yi.org> wrote:
>
> > 2006-05-31
> > <11************ *********@c74g2 000cwc.googlegr oups.com>,
> > Peter Nilsson wrote:

> > > int foo() { }

> > The standard makes a very clear distinction between empty
> > brackets in a declaration not part of a definition,
> > and empty brackets that _are_ in part of a definition.

> Where?

What?

N869
Index

( ) (parentheses punctuator), 6.7.5.3, 6.8.4, 6.8.5
[ ] (brackets punctuator), 6.7.5.2, 6.7.8
{ } (braces punctuator), 6.7.2.2, 6.7.2.3, 6.7.8, 6.8.2


Are you being dense?


I am dense.


My point actually is that I always advocate using
C standard terminology when discussing the C standard
on this newsgroup.

--
pete
Jun 26 '06 #32
On Mon, 26 Jun 2006 02:30:03 GMT, in comp.lang.c , pete
<pf*****@mindsp ring.com> wrote:

The example shown had empty parentheses and empty braces
and he was saying something that you suggest was false
about empty brackets.
It was, obviously, contained within the brackets. -)
So where's my clue as to what he's talking about?


Two nations divided by a common language indeed.

For the record, brackets come in three flavours, square, wiggly and
plain.

gd&r
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jun 26 '06 #33

Mark McIntyre wrote:

For the record, brackets come in three flavours, square, wiggly and
plain.


I've heard them called "curly, "squiggly", and "squirrely" , but
I don't believe i've ever seen them called "wiggly" before. (I think I
usually call them "curly brackets" or sometimes "braces").

-Bill

Jun 27 '06 #34
Mark McIntyre wrote:
On Mon, 26 Jun 2006 02:30:03 GMT, in comp.lang.c , pete
<pf*****@mindsp ring.com> wrote:

The example shown had empty parentheses and empty braces
and he was saying something that you suggest was false
about empty brackets.


It was, obviously, contained within the brackets. -)
So where's my clue as to what he's talking about?


Two nations divided by a common language indeed.

For the record, brackets come in three flavours, square, wiggly and
plain.


You forgot <pointy>.

--
Chris "ouch!" Dollin
"No-one here is exactly what he appears." G'kar, /Babylon 5/

Jun 27 '06 #35
Mark McIntyre wrote:
For the record, brackets come in three flavours, square, wiggly and
plain.


Four flavours:

(normal brackets)
[square brackets]
{curly brackets}
<angle brackets>

Even a simple C program uses all four flavours:

#include <stdio.h> // angle brackets
int main(int argc, char **argv) // normal brackets
{
printf("program name: %s\n",
argv[0] ? argv[0] // square brackets
: "none");
return 0;
} // curly brackets

Someone tell me, does one learn PODMAS instead of BODMAS in the USA?
(Brackets, Orders, Division/Multiplication, Addition/Subtraction)

--
Simon.
Jun 27 '06 #36
Simon Biber posted:

Someone tell me, does one learn PODMAS instead of BODMAS in the USA?

I actually learned BOMDAS at school, rather than "BODMAS".

Brackets
Off
Multiply
Divide
Add
Substract
Looks like we'd interpret the following differently:
5 * 4 / 2 * 5


If we multiply first, we get 2.
If we divide first, we get 50.
But of course C gives them equal precedence and works left to right, so
we'd get 50.

--

Frederick Gotham
Jun 27 '06 #37
Frederick Gotham wrote:
Simon Biber posted:

Someone tell me, does one learn PODMAS instead of BODMAS in the USA?

I actually learned BOMDAS at school, rather than "BODMAS".

Brackets
Off
Multiply
Divide
Add
Substract


It makes no difference. Either way you have to remember that Multiply
and Divide have equal precedence and are evaluated left to right.
Similarly, Add and Subtract have equal precedence and are evaluated left
to right.
Looks like we'd interpret the following differently:
5 * 4 / 2 * 5
If we multiply first, we get 2.
If we divide first, we get 50.


The correct answer is 50, however it's just by chance that this is also
achieved by dividing first.

In general you do not achieve the correct answer by multiplying first or
by dividing first, but rather by working left to right.

--
Simon.
Jun 27 '06 #38
Simon Biber posted:

In general you do not achieve the correct answer by multiplying first or
by dividing first, but rather by working left to right.

Yes I am well aware of how C operator precedence works -- I was referring
to the way human beings do math.

On the European side of the Atlantic, we learn BOMDAS rather than BODMAS,
and this would lead us to interpret the following line differently:

4 * 12 / 3 * 8
C compiler interpretation: 128

American interpretation: 128

European interpretation: 2

--

Frederick Gotham
Jun 27 '06 #39
On Tue, 27 Jun 2006 18:56:04 GMT, in comp.lang.c , Frederick Gotham
<fg*******@SPAM .com> wrote:
On the European side of the Atlantic, we learn BOMDAS rather than BODMAS,
and this would lead us to interpret the following line differently:

4 * 12 / 3 * 8
C compiler interpretation: 128

American interpretation: 128

European interpretation: 2


Euh. only if you put in some brackets. I can't otherwise see how four
times twelve thirds times eight can equal two.

But then, everything *is* bigger in the States. :-)
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jun 27 '06 #40

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

Similar topics

4
2154
by: Carsten Spieß | last post by:
Hello all, i have a problem with a template constructor I reduced my code to the following (compiled with gcc 2.7.2) to show my problem: // a base class class Base{}; // two derived classes
5
6069
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user hits the right and left keys to move this insertion point (cursor) Here is the problem:
7
5201
by: Mike D. | last post by:
I have a problem with a dynamic library I am developing, but it is really more of a pointer issue than anything else. Hopefully someone here can lend me some assistance or insight into resolving this. Ok... here goes.... I have a function that passes a pointer to a string to another function. For example: int FunctionA ()
10
4142
by: Kieran Simkin | last post by:
Hi, I wonder if anyone can help me, I've been headscratching for a few hours over this. Basically, I've defined a struct called cache_object: struct cache_object { char hostname; char ipaddr; };
204
13167
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 = {0,1,2,4,9};
7
2050
by: Marcelo | last post by:
Hi everybody, I don't understand why I am having a problem in this code. The problem is that my pointer *phist in main method, it is declared. Then I send the pointer to my method, and this method creates a new object (a Matrix) for it. I suppose that after the new operator, my pointer is pointing to an object, so when the method has finished, the very first pointer is still poitint to the created method; however this is not working,...
51
10585
by: Joe Van Dyk | last post by:
When you delete a pointer, you should set it to NULL, right? Joe
2
2853
by: toton | last post by:
Hi, This is continuation of topic pointer & reference doubt. http://groups.google.com/group/comp.lang.c++/browse_thread/thread/df84ce6b9af561f9/76304d7d77f6ccca?lnk=raot#76304d7d77f6ccca But I think it is better to have a new topic rather than continuing on old one. As now I am sure pointer to reference and reference to pointer are freely convertable, the potential danger lies in the first one. Pointer may be NULL, but reference should...
9
3025
by: junky_fellow | last post by:
Hi, To print the pointer using printf(), we convert it to (void *) . printf("%p",(void *)ptr); My question is how printf() determine which type of pointer is passed to it and prints its value accordingly ? I have this doubt as different pointers may have different representation and different size. So, how does printf determine
6
2541
by: worlman385 | last post by:
For pointer and non-pointer initialization of an object like MyCar mycar; MyCar* mycar = new MyCar(); I heard from other people saying if object i create must live outside scape, then I use pointer version, else if only use object for a limited scope, then use non-pointer version. Does limited scope means the object is only used in the same function
0
9932
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
10728
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...
1
10833
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
10405
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...
1
7959
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
7114
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
5782
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...
0
5980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.