Hello all,
char a[2]
char* u8
int u32
u8 = &u32
Cant we referance a char pointer to int ?
Why is this not possible?
I want to transfer all the data from array a to u32.
Thanks 11 1370
abhaybhat wrote:
Hello all,
char a[2]
char* u8
int u32
u8 = &u32
You want to assign an int* to a char*? That sounds
like a recipe for confusion.
Cant we referance a char pointer to int ?
Why is this not possible?
It's /possible/. It's likely not /wise/, depending.
I want to transfer all the data from array a to u32.
u32 = (a[1] << 8) + a[0];
(where `8` should likely be spelled `CHAR_BIT` and `1`
and `0` may need interchanging depending on what
endianness you've picked for the bytes.)
No pointer-type-games needed.
--
"Where the shadows run from themselves." /White Room/
Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England
abhaybhat wrote:
Hello all,
char a[2]
char* u8
int u32
u8 = &u32
Cant we referance a char pointer to int ?
Not portably. A pointer of type T* may hold either the value NULL or the
address of an object of type T. The special pointer void* may hold NULL
or the address of any object type, but may not be deferenced. Nor can
you do pointer arithmetic on void*.
Why is this not possible?
That's how the language has been designed. The main reason is
implementabilit y on systems where different pointer types may be
incompatible with each other, i.e., their size may be different, their
representation may be different, etc.
<snip>
On Thu, 12 Jun 2008 05:09:39 -0700 (PDT), abhaybhat
<ab*****@gmail. comwrote:
>Hello all,
char a[2] char* u8 int u32
u8 = &u32
Cant we referance a char pointer to int ?
Not implicitly.
>Why is this not possible?
It is possible; use a cast.
> I want to transfer all the data from array a to u32.
Use memcpy. But why? Is there any guarantee that the result will be
in any way meaningful? Based on you names, it looks like a will
occupy only half of u32. What will you do with the other half?
You could put a and u32 in a union and not need to transfer anything.
Remove del for email
On Jun 12, 4:07 pm, Barry Schwarz <schwa...@dqel. comwrote:
On Thu, 12 Jun 2008 05:09:39 -0700 (PDT), abhaybhat
<abha...@gmail. comwrote:
Hello all,
char a[2]
char* u8
int u32
u8 = &u32
Cant we referance a char pointer to int ?
Not implicitly.
char *p = 0;
On 12 Jun, 13:09, abhaybhat <abha...@gmail. comwrote:
char a[2]
char* u8
int u32
I'm never too fond of things like u8 and u32,
but if you must use them then most people would expect
the "u" to stand for unsigned. char may or may not be unsigned
int is never unsigned.
If u8 is 8-bits and u32 is 32-bits then a u32 will
consist of 4 u8s not 2 as you imply.
u8 = &u32
Cant we referance a char pointer to int ?
Why is this not possible?
I want to transfer all the data from array a to u32.
I bet you don't.
--
Nick Keighley
why isn't there an obfuscated C++ contest? vi******@gmail. com wrote:
On Jun 12, 4:07 pm, Barry Schwarz <schwa...@dqel. comwrote:
>On Thu, 12 Jun 2008 05:09:39 -0700 (PDT), abhaybhat
<abha...@gmail .comwrote:
>Hello all,
>char a[2] char* u8 int u32
>u8 = &u32
>Cant we referance a char pointer to int ?
Not implicitly.
char *p = 0;
That's not an example of "referance a char pointer to int"
(by which the OP seems to mean "assign an int pointer value
to a char pointer variable").
--
"The letter was not unproductive." /Mansfield Park/
Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England vi******@gmail. com wrote:
On Jun 12, 3:38 pm, Chris Dollin <chris.dol...@h p.comwrote:
>abhaybhat wrote:
Hello all,
char a[2]
char* u8
int u32
u8 = &u32
You want to assign an int* to a char*? That sounds like a recipe for confusion.
Cant we referance a char pointer to int ?
Why is this not possible?
It's /possible/. It's likely not /wise/, depending.
I want to transfer all the data from array a to u32.
u32 = (a[1] << 8) + a[0];
(where `8` should likely be spelled `CHAR_BIT` and `1` and `0` may need interchanging depending on what endianness you've picked for the bytes.)
AFAIK that won't work if int's size is char's size as well. (*if* 8 is
replaced with CHAR_BIT)
If `sizeof(int)` equals `sizeof(char)`, what the OP wants to do
cannot be done at all (and their chosen names would be misleading).
Quarts & pint pots.
--
"Giving my opinion / to whoever's there." /Wonderland/
Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN
On Jun 12, 4:27 pm, Chris Dollin <chris.dol...@h p.comwrote:
vipps...@gmail. com wrote:
On Jun 12, 3:38 pm, Chris Dollin <chris.dol...@h p.comwrote:
abhaybhat wrote:
Hello all,
char a[2]
char* u8
int u32
u8 = &u32
You want to assign an int* to a char*? That sounds
like a recipe for confusion.
Cant we referance a char pointer to int ?
Why is this not possible?
It's /possible/. It's likely not /wise/, depending.
I want to transfer all the data from array a to u32.
u32 = (a[1] << 8) + a[0];
(where `8` should likely be spelled `CHAR_BIT` and `1`
and `0` may need interchanging depending on what
endianness you've picked for the bytes.)
AFAIK that won't work if int's size is char's size as well. (*if* 8 is
replaced with CHAR_BIT)
If `sizeof(int)` equals `sizeof(char)`, what the OP wants to do
cannot be done at all (and their chosen names would be misleading).
Quarts & pint pots.
Their names are misleading nonetheless.
Using <stdint.hand uintN_t it can be done:
uint8_t arrayu8[2];
/*...*/
uint32_t u32 = arrayu8[1] << 8 | arrrayu8[0];
It is not however portable to use << CHAR_BIT or >CHAR_BIT with any
integer expression. vi******@gmail. com wrote:
On Jun 12, 4:27 pm, Chris Dollin <chris.dol...@h p.comwrote:
>vipps...@gmail .com wrote:
On Jun 12, 3:38 pm, Chris Dollin <chris.dol...@h p.comwrote: abhaybhat wrote:
Hello all,
char a[2]
char* u8
int u32
u8 = &u32
>You want to assign an int* to a char*? That sounds like a recipe for confusion.
Cant we referance a char pointer to int ?
Why is this not possible?
>It's /possible/. It's likely not /wise/, depending.
I want to transfer all the data from array a to u32.
> u32 = (a[1] << 8) + a[0];
>(where `8` should likely be spelled `CHAR_BIT` and `1` and `0` may need interchanging depending on what endianness you've picked for the bytes.)
AFAIK that won't work if int's size is char's size as well. (*if* 8 is
replaced with CHAR_BIT)
If `sizeof(int)` equals `sizeof(char)`, what the OP wants to do cannot be done at all (and their chosen names would be misleading). Quarts & pint pots.
Their names are misleading nonetheless.
Using <stdint.hand uintN_t it can be done:
uint8_t arrayu8[2];
/*...*/
uint32_t u32 = arrayu8[1] << 8 | arrrayu8[0];
It is not however portable to use << CHAR_BIT or >CHAR_BIT with any
integer expression.
When those expressions are not defined, the OP can't do what they
want anyway. When they can do what they want (or at least my
reading of it), the shifts are well-defined.
I agree that the code must be guarded somehow against undefinedness.
--
"I am trying to say that you have no choice." /The Courts of Chaos/
Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Eric Kincl |
last post by:
Hello,
I have an array of data in PHP. I would like to insert each member of the
array into it's own row in SQL. The array is of variable length, so it
would have to be dynamic code. How would I go about this? Would I stick
the SQL querry generation and actual querry into a while loop? This would
generate a lot of traffic between the SQL...
|
by: Costa Lino |
last post by:
Hi All,
I have a DataSet with xml file and I want to make a querry like this
DataView dv = new DataView(mytable);
dv.RowFilter = " Impression < ( MaxImpressions) ";
Impression et MaxImpressions is collumns in my table the same querry access
database is working but her is return 0
|
by: ranjeet.gupta |
last post by:
Dear All
As I was going through the Recent replies on the realloc(),
I got some question and my annalysis on that, so regarding on these
please guide me where I fail on the theoritical and practical
Knowledge. I am not able to read all the thread in the replies as
due to some problem in the web server.
Point 1.
|
by: Lalatendu Das |
last post by:
hi
Please someone give a real time implimentation of a function pointer.
where exactly we need a function pointer very much . if it is in terms
of code i will be happy enough .
thanks in advance
|
by: Clownfish |
last post by:
OK, I'm having a brain freeze.
I have a table like this:
Office Name Phone
----------------------------------
SG Larry 555-1212
SG Moe 553-4444
SG Curly 666-8888
PO Ren 222-9999
| |
by: Steve Kiss |
last post by:
Hi. I am developping a site for which one of the pages uses querry strings to pass some parameters. I can use the querry strings if I call the page from a plain html anchor. However, when I add the URL to the sitemap I get the following error:
The 'url' property had a malformed URL
This is the offending URL:...
|
by: nj2md |
last post by:
Can some one assist with a querry. I need to know the code to querry a database to find the number of female and males that make over 50K a year and how to get capital gains and loses from the same database. Finally the code to count by occupation each country in the database. I
Thanks in advance. I hope that this is enough data to assist...
|
by: getmeidea |
last post by:
I have the following tables,
1> employee_master(emp_id int primary key, emp_name varchar(100));
2> employee_salary_payment(salary_rid int primary key, emp_id int, sal_date date, paid_amt int);
The tables, employee_master and employee_salary_payment have one to many relation.
I need to list the salary payment done for the employee having id...
|
by: dipalichavan82 |
last post by:
i came across a article, where it was mentioned if we want a dynamic querry to fire then use parameterized querry
e.g.
string inputcity=textbox.text;
SqlCommand cmd = new SqlCommand("select * from Customers where city=
'" + inputCity + " ' ";
Don't ever build a query this way!
as this leads to hacking.
instaed do it like this:
|
by: bowlderyu |
last post by:
Hello, all.
If a struct contains a character strings, there are two methods to
define the struct, one by character array, another by character pointer.
E.g,
//Program for struct includeing character strings, test1.c
#include <stdio.h>
#define LEN 20
struct info {
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |