473,405 Members | 2,167 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,405 software developers and data experts.

Passing pointer argument to function error?

Hello - Isn't this right? :

Expand|Select|Wrap|Line Numbers
  1. void Function(int *d, const int c, int n);
  2.  
  3. void Function(int *d, const int c, int n)
  4. {
  5.    while(n) { *(d++) = c; }
  6. }
  7.  
  8. Function(&var1, 0, sizeof(thing));
  9.  
  10.  
Why do I get a warning : "passing arg1 of "Function" from incompatible pointer type" ??

thanks!
Jul 25 '08 #1
5 1391
JosAH
11,448 Expert 8TB
What is the type of 'var1'?

kind regards,

Jos
Jul 25 '08 #2
What is the type of 'var1'?

kind regards,

Jos

oh - var1 is a structure....

Expand|Select|Wrap|Line Numbers
  1. typedef struct st_var
  2. {
  3.    Athing arr[max];
  4.    int limit1;
  5.    int limit 2;
  6. } Var;
  7.  
  8. Var var1;
  9.  
please advise..
thank you.
Jul 25 '08 #3
boxfish
469 Expert 256MB
Hi,
I don't get it. How can you pass a value of type st_var* into an argument of type int*? Is that really what you want to do? I would complain too, if I were the compiler. If this function has to work with any type, you could use a void*, but I don't think you can increment those. Why is the parameter of type int*?
Jul 26 '08 #4
Banfa
9,065 Expert Mod 8TB
boxfish is right you can't increment points of type void *. To be able to increment a pointer to a type you have to know the types size and by definition the size of void is 0.

This looks to me like a self implementation of the library function memset. Assuming you can't use memset then you need to use void * as memset does and boxfish suggests. You will then be able to pass a pointer to anything to your function.

Then internally to the function copy the void * to a char * variable and use that in you loop.
Jul 26 '08 #5
arnaudk
424 256MB
OP: Even when you get your types right, that Function will either run forever if n is non-zero or do strictly nothing otherwise, the only exception being if c=0 and the address of n is eventually reached by incrementing d. I'm not sure this is what you intended.
Jul 28 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
10
by: Pete | last post by:
Can someone please help, I'm trying to pass an array to a function, do some operation on that array, then return it for further use. The errors I am getting for the following code are, differences...
9
by: Juggernaut | last post by:
I am trying to create a p_thread pthread_create(&threads, &attr, Teste, (void *)var); where var is a char variable. But this doesnt't work, I get this message: test.c:58: warning: cast to pointer...
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
17
by: Charles Sullivan | last post by:
The library function 'qsort' is declared thus: void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); If in my code I write: int cmp_fcn(...); int...
3
by: sd2004 | last post by:
I am still learning, could someone show/explain to me how to fix the error. I can see it is being wrong but do not know how to fix. could you also recommend a book that I can ref. to ?...
5
by: steven_orocos | last post by:
Hi, I'm tryin to pass a funtion as an argument in another funtion. This code works ---------------------------------- typedef void (*func)(int); void test1(int a){cout<<"1";} void...
5
by: mshaaban | last post by:
Hello, In my code I have a large static 2D arrays defined as: code: #define LONMAX 1440 #define LATMAX60 480 void main (int argc, char *argv)
8
by: S. | last post by:
Hi all, Can someone please help me with this? I have the following struct: typedef struct { char *name; int age; } Student;
18
by: sanjay | last post by:
Hi, I have a doubt about passing values to a function accepting string. ====================================== #include <iostream> using namespace std; int main() {
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.