473,320 Members | 1,719 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,320 software developers and data experts.

warning C4047:

Hello, It's just a warning, but can anybody explain to me what this warning is:

warning C4047: '=' : 'unsigned int ' differs in levels of indirection from 'void *'

#include <stdio.h>
void swap(int *x, int *y);
int main()
{
int x[2]={1,6}, y[2]={1,10};
printf("Before the function swap, x = %d and y = %d\n\n", x, y);
swap(&x, &y);
printf("After the function swap, x = %d and y = %d\n\n", x, y);
return 0;
}
void swap(int *x, int *y)
{
int temp = *x;
*x = *y;
*y = temp;
}
Nov 13 '05 #1
10 6128
io****************@web.de (isxyos) wrote:
Hello, It's just a warning, but can anybody explain to me what this warning is:

warning C4047: '=' : 'unsigned int ' differs in levels of indirection from 'void *'

#include <stdio.h>
void swap(int *x, int *y);
int main()
{
int x[2]={1,6}, y[2]={1,10}; Make this: int x = 6, y = 10;
printf("Before the function swap, x = %d and y = %d\n\n", x, y);
swap(&x, &y);
printf("After the function swap, x = %d and y = %d\n\n", x, y);
return 0;
} Or, if x and y had to be arrays, change x, y to *x, *y in the printf()s,
and change swap( &x, &y ) to swap( x, y );
Alas, with the identical values you supplied for x[0] and y[0], you
won't notice if you'd invoced swap() at all...
void swap(int *x, int *y)
{
int temp = *x;
*x = *y;
*y = temp;
}


--
6 * 9 = 42 (base 13)
Nov 13 '05 #2
isxyos <io****************@web.de> wrote:
Hello, It's just a warning, but can anybody explain to me what this warning is: warning C4047: '=' : 'unsigned int ' differs in levels of indirection from 'void *' #include <stdio.h>
void swap(int *x, int *y);
int main()
{
int x[2]={1,6}, y[2]={1,10};
printf("Before the function swap, x = %d and y = %d\n\n", x, y);
swap(&x, &y);
printf("After the function swap, x = %d and y = %d\n\n", x, y);
return 0;
}
void swap(int *x, int *y)
{
int temp = *x;
*x = *y;
*y = temp;
}


Don't know what the error message is exactly supposed to mean, are
you sure you got it for the program you posted (I can't see neither
any 'void *' nor an 'unsigned int' in the whole program...)? But
the problem is obvious: you're declaring x and y to be arrays of
two integers each but in the following you consistently treat them
as if they were simple integers. So either change your program so
that they are both declared to be simple integers or append every-
where else if you mean the first or the second element of the array.

Regards, Jens
--
_ _____ _____
| ||_ _||_ _| Je***********@physik.fu-berlin.de
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring
Nov 13 '05 #3
isxyos wrote:

Hello, It's just a warning, but can anybody explain to me what this warning is:

warning C4047: '=' : 'unsigned int ' differs in levels of indirection from 'void *'

#include <stdio.h>
void swap(int *x, int *y);
int main()
{
int x[2]={1,6}, y[2]={1,10};
printf("Before the function swap, x = %d and y = %d\n\n", x, y);
x and y arent' integers.
What do you think is supposed to be printed ?
swap(&x, &y);
swap(x, y);

In this context, x and y are converted to pointers to their
respective first elements.
printf("After the function swap, x = %d and y = %d\n\n", x, y);
return 0;
}
void swap(int *x, int *y)
{
int temp = *x;
*x = *y;
*y = temp;
}

#include <stdio.h>

void swap(int *x, int *y);

int main(void)
{
int x[2]={1,2}, y[2]={3,4};

printf("Before the function swap, x[0] = %d and y[0] = %d\n",
x[0], y[0]);
printf("Before the function swap, x[1] = %d and y[1] = %d\n\n",
x[1], y[1]);
swap(x, y);
swap(x + 1, y + 1);
printf("After the function swap, x[0] = %d and y[0] = %d\n",
x[0], y[0]);
printf("After the function swap, x[1] = %d and y[1] = %d\n\n",
x[1], y[1]);
return 0;
}

void swap(int *x, int *y)
{
int temp = *x;

*x = *y;
*y = temp;
}

--
pete
Nov 13 '05 #4
io****************@web.de (isxyos) wrote:
Hello, It's just a warning, but can anybody explain to me what this warning is:

warning C4047: '=' : 'unsigned int ' differs in levels of indirection from 'void *'

#include <stdio.h>
void swap(int *x, int *y);
int main()
{
int x[2]={1,6}, y[2]={1,10}; Make this: int x = 6, y = 10;
printf("Before the function swap, x = %d and y = %d\n\n", x, y);
swap(&x, &y);
printf("After the function swap, x = %d and y = %d\n\n", x, y);
return 0;
} Or, if x and y had to be arrays, change x, y to *x, *y in the printf()s,
and change swap( &x, &y ) to swap( x, y );
Alas, with the identical values you supplied for x[0] and y[0], you
won't notice if you'd invoced swap() at all...
void swap(int *x, int *y)
{
int temp = *x;
*x = *y;
*y = temp;
}


--
6 * 9 = 42 (base 13)
Nov 13 '05 #5
isxyos wrote:
warning C4047: '=' : 'unsigned int ' differs in levels of indirection from 'void *'


Doesn't your compiler give you line numbers?

--
Tom Zych
This email address will expire at some point to thwart spammers.
Permanent address: echo 'g******@cbobk.pbz' | rot13
Nov 13 '05 #6
isxyos wrote:
warning C4047: '=' : 'unsigned int ' differs in levels of indirection from 'void *'


Doesn't your compiler give you line numbers?

--
Tom Zych
This email address will expire at some point to thwart spammers.
Permanent address: echo 'g******@cbobk.pbz' | rot13
Nov 13 '05 #7
Tom Zych <tz******@pobox.com> wrote in message news:<3F***************@pobox.com>...
isxyos wrote:
warning C4047: '=' : 'unsigned int ' differs in levels of indirection from 'void *'


Doesn't your compiler give you line numbers?


Here is what my compiler says:

dresnick(531)$ gcc -Wall -ansi -pedantic foo.c -o foo
foo.c: In function `main':
foo.c:6: warning: int format, pointer arg (arg 2)
foo.c:6: warning: int format, pointer arg (arg 3)
foo.c:7: warning: passing arg 1 of `swap' from incompatible pointer type
foo.c:7: warning: passing arg 2 of `swap' from incompatible pointer type
foo.c:8: warning: int format, pointer arg (arg 2)
foo.c:8: warning: int format, pointer arg (arg 3)

The program as written doesn't make much sense. If the purpose is to
swap in place arrays of integers, then the sizes of the arrays need
to be provided to the swap function (and they'd better be the same
size). If it is to just swap the first elements of arrays of integers,
perhaps it would be more clearly invoked as:

swap(&x[0], &y[0]);
(though swap(x,y); should also be fine).

Or are the integer arrays red herrings? In any case, the other complaint is
that you are passing a pointer to the %d specifier, when you mean to be
dereferencing the pointer and passing the int...

-David
Nov 13 '05 #8
Tom Zych <tz******@pobox.com> wrote in message news:<3F***************@pobox.com>...
isxyos wrote:
warning C4047: '=' : 'unsigned int ' differs in levels of indirection from 'void *'


Doesn't your compiler give you line numbers?


Here is what my compiler says:

dresnick(531)$ gcc -Wall -ansi -pedantic foo.c -o foo
foo.c: In function `main':
foo.c:6: warning: int format, pointer arg (arg 2)
foo.c:6: warning: int format, pointer arg (arg 3)
foo.c:7: warning: passing arg 1 of `swap' from incompatible pointer type
foo.c:7: warning: passing arg 2 of `swap' from incompatible pointer type
foo.c:8: warning: int format, pointer arg (arg 2)
foo.c:8: warning: int format, pointer arg (arg 3)

The program as written doesn't make much sense. If the purpose is to
swap in place arrays of integers, then the sizes of the arrays need
to be provided to the swap function (and they'd better be the same
size). If it is to just swap the first elements of arrays of integers,
perhaps it would be more clearly invoked as:

swap(&x[0], &y[0]);
(though swap(x,y); should also be fine).

Or are the integer arrays red herrings? In any case, the other complaint is
that you are passing a pointer to the %d specifier, when you mean to be
dereferencing the pointer and passing the int...

-David
Nov 13 '05 #9
bd
isxyos wrote:
Hello, It's just a warning, but can anybody explain to me what this
warning is:

warning C4047: '=' : 'unsigned int ' differs in levels of indirection from
'void *'
#include <stdio.h>
void swap(int *x, int *y);
int main()
{
int x[2]={1,6}, y[2]={1,10};
printf("Before the function swap, x = %d and y = %d\n\n", x, y);
x and y are pointers to ints (well, arrays that decay to pointers to ints),
not ints. Use:

printf("Before the function swap, x = %p and y = %p\n\n",
(void *)x, (void *)y);
swap(&x, &y);
Try this:
swap(x, y);

Of course, this won't work the way you expect - the function will affect
only the first element in the array.

printf("After the function swap, x = %d and y = %d\n\n", x, y);
See above about %p. Also, this won't change, as x and y have fixed locations
in memory (unless you recurse).
return 0;
}
void swap(int *x, int *y)
{
int temp = *x;
*x = *y;
*y = temp;
}

--
Lead me not into temptation... I can find it myself.

Nov 13 '05 #10
bd
isxyos wrote:
Hello, It's just a warning, but can anybody explain to me what this
warning is:

warning C4047: '=' : 'unsigned int ' differs in levels of indirection from
'void *'
#include <stdio.h>
void swap(int *x, int *y);
int main()
{
int x[2]={1,6}, y[2]={1,10};
printf("Before the function swap, x = %d and y = %d\n\n", x, y);
x and y are pointers to ints (well, arrays that decay to pointers to ints),
not ints. Use:

printf("Before the function swap, x = %p and y = %p\n\n",
(void *)x, (void *)y);
swap(&x, &y);
Try this:
swap(x, y);

Of course, this won't work the way you expect - the function will affect
only the first element in the array.

printf("After the function swap, x = %d and y = %d\n\n", x, y);
See above about %p. Also, this won't change, as x and y have fixed locations
in memory (unless you recurse).
return 0;
}
void swap(int *x, int *y)
{
int temp = *x;
*x = *y;
*y = temp;
}

--
Lead me not into temptation... I can find it myself.

Nov 13 '05 #11

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

Similar topics

2
by: isxyos | last post by:
Hello, It's just a warning, but can anybody explain to me what this warning is: warning C4047: '=' : 'unsigned int ' differs in levels of indirection from 'void *' #include <stdio.h> void...
3
by: Bill Burris | last post by:
How do I find what is causing this warning from the Linker? If I use /NODEFAULTLIB I get hundreds of undefined symbols. LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other...
3
by: DJTN | last post by:
I'm getting the following error when I try to compile my setup project in VS 2002. I have re-installed the .net framework 1.1 and it didnt solve the problem. WARNING: Unable to find dependency...
1
by: spanov | last post by:
i've got problem installing python-2.3.5 from sources on FreeBSD 5.3 root@server# ./configure > conf_log configure: WARNING: curses.h: present but cannot be compiled configure: WARNING:...
5
by: pkirk25 | last post by:
I like to keep warnings to a minimum and am find this one cropping up a lot. struct auction_bargains bargainList; struct auction_bargains *pBargainList = &bargainList; I am creating an array...
4
by: Sam Tan | last post by:
Hello got two warning when compiling , the .exe file works fine with these warning but i prefer to get rid of them :) if anyone can point me to a general website for indirection warnings that...
92
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
4
by: cody | last post by:
It is possible to declare and use/instantiate a class with a uninitialized readonly field without even a compiler warning. Why don't I get warnings? public class Stuff { public readonly int a;...
2
by: mullhead | last post by:
This warning keeps popping up... box.c(50) : warning C4047: '=' : 'box *' differs in levels of indirection from 'size_t' 49 pBox = malloc(sizeof(box)*lineCount-1); 50 assert(pBox =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.