Re: C Pointer problem



Default User said:

Markus wrote:

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.

Did this really compile without any warnings or errors?

No.

foo.c:2: warning: no previous prototype for `pass'
foo.c: In function `pass':
foo.c:3: warning: unused variable `x'
foo.c: At top level:
foo.c:6: warning: function declaration isn't a prototype
foo.c:6: warning: return type of `main' is not `int'
foo.c: In function `main':
foo.c:8: warning: passing arg 1 of `pass' from incompatible pointer type

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
.



Relevant Pages

  • Re: help me !
    ... test.c:12: warning: suggest parentheses around assignment used as truth value ... include it /after/ the headers in sys/, ... > void init_daemon ... > int pid; ...
    (comp.os.linux.development.apps)
  • Re: Lvalue Required(wierd)...
    ... main must have a return type of int ... Warning MAIN.C 3: Call to function 'clrscr' with no prototype ... int main (void) ...
    (comp.lang.c)
  • sound driver for pc speaker (long)
    ... myaudio.h:46: warning: initialization from incompatible pointer type ... myaudio.c:17: warning: type defaults to `int' in declaration of `type ...
    (comp.os.linux.development.system)
  • fgets() - supposed to be simple :)
    ... void menu; ... int validate(char *a); ... another.c:62: warning: assignment makes pointer from integer without a ...
    (comp.lang.c)
  • Re: [kde] konstruct, nother problem
    ... x_4.cpp:4271: warning: `class x_KBookmarkOwner' has virtual functions ... In function `void xcall_KCodecs(short int, void*, ...
    (Linux-Kernel)