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;
} 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)
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
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 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)
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
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
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
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
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.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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:...
|
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...
|
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...
|
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);
|
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;...
|
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 =...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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...
|
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,...
|
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,...
|
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...
| |