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

convert Void * to an int using GCC 4.1.1

41
Hi ,

I have the following where i want to take a void * and convert it to an int
void *contending(void *arg)
{
int delta = (void *) arg;
}

error: invalid conversion from void* to int

Any ideas how i can achieve this using GCC 4.1.1

Any help much appreciated !
Nov 7 '07 #1
5 6801
sicarie
4,677 Expert Mod 4TB
As far as I know, you can't have a pointer to a void. Void is a keyword to tell the compiler not to expect anything - as in the return type of the function you have. Where did you get *arg? Does it have a type in your main()?
Nov 7 '07 #2
How about using this:
Expand|Select|Wrap|Line Numbers
  1.    int delta = (int) arg;
  2.  
Nov 7 '07 #3
nano2
41
How about using this:
Expand|Select|Wrap|Line Numbers
  1.    int delta = (int) arg;
  2.  
Thanks all ....
Goit it sorted using this -- some comoilers threat void differently

int delta= (long int)arg;
Nov 8 '07 #4
sicarie
4,677 Expert Mod 4TB
Thanks all ....
Goit it sorted using this -- some comoilers threat void differently

int delta= (long int)arg;
yeah, nano2, I just wanted to say thanks, I'd never seen that, so I spent the last few days researching other uses of void like that. You learn something new every day...
Nov 8 '07 #5
There so many ways of doing it check this out:

Expand|Select|Wrap|Line Numbers
  1. void *contending(void *arg)
  2. {
  3. int *delta = (int *)arg;
  4. printf("%d\n",delta); //printing out to sreen
  5. }
  6.  
delta is a pointer to integer then we cast arg which is a void * unto an integer of int.

When passing a paramater when calling function is like this: contending((int*)3100); we cast it like that.

I Hope i helped !!! =)
Nov 17 '10 #6

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

Similar topics

1
by: tolo | last post by:
Hi, how to: using dts convert row in table to column. i have table: col1,col2 b1 , 1 b2 , 2 b1 , 4 b3 , 3 b2 , 5
188
by: infobahn | last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
3
by: Dennis | last post by:
I am trying to convert a bitmap to a JPEG MemoryStream and return a Byte array containing the resulting JPEG Image as follows: Public Function BmpToJPEG(ByVal BitMapIn As Bitmap, ByVal Quality As...
3
by: Ray Gardener | last post by:
I searched around but couldn't find any previous discussion on this, so... I have a macro that implements a common memory disposal function, e.g.: #define safe_free(void* pv) if(pv) {...
5
by: MattWilson.6185 | last post by:
Hi! I have had this problem several times before, and each time I have been turned back forced to find another way. But not this time... How can you cast a Class::* into a void *. For this...
7
by: Charles Zhang | last post by:
I want to know to the following in a safe manner (the following code will be dangerous if p does not contain a pointer to MyClass). I would like someone to show me a better way (either throw an...
2
by: xyligan | last post by:
i`m trying to get image from scanner throw dll (c++), which returns data in void * type. so googled.. i found: Marshal.Copy(new IntPtr((byte*)result.buffer), byte_arr,0, size); ...
1
by: osman7king | last post by:
hello all... I'm trying to convert the query which uses outer join statment from Oracle to PostgreSQL but I have some problems with this query may some one help me for this problem? SELECT ...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.