473,387 Members | 1,619 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,387 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 6139
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.