#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int main()
{
unsigned char *c;
c = malloc(sizeof(u nsigned char));
printf("size of unsigned char: %d\n", sizeof(unsigned char));
printf("size of c: %d\n", sizeof(c));
return 0;
}
When I execute this, it says that size of "unsigned char" is "1" & size
of "c" is "4". isn't that strange?
( gcc version 4.0.0 20050519 (Red Hat 4.0.0-8) ) 18 1425
"Parahat Melayev" <pa*****@gmail. com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. . #include <stdio.h> #include <stdlib.h> #include <limits.h>
int main() { unsigned char *c; c = malloc(sizeof(u nsigned char)); printf("size of unsigned char: %d\n", sizeof(unsigned char)); printf("size of c: %d\n", sizeof(c)); return 0; }
When I execute this, it says that size of "unsigned char" is "1" & size of "c" is "4". isn't that strange?
Nope. C isn't a char, it's a pointer (to a char).
Alex
oh yeah that is right :) panic
tnx
Parahat Melayev wrote: #include <stdio.h> #include <stdlib.h> #include <limits.h>
int main() { unsigned char *c; c = malloc(sizeof(u nsigned char)); printf("size of unsigned char: %d\n", sizeof(unsigned char)); printf("size of c: %d\n", sizeof(c)); return 0; }
When I execute this, it says that size of "unsigned char" is "1" & size of "c" is "4". isn't that strange?
what is c ????
c is the pointer which is going to hold the address which is of the
char type.
malloc will return the address of the allocated memory.
and so c holds the address, which is int.
c = malloc(sizeof(u nsigned char));
HTH
ranjeet ( gcc version 4.0.0 20050519 (Red Hat 4.0.0-8) )
Parahat Melayev wrote: #include <stdio.h> #include <stdlib.h> #include <limits.h>
int main() { unsigned char *c; c = malloc(sizeof(u nsigned char)); printf("size of unsigned char: %d\n", sizeof(unsigned char)); printf("size of c: %d\n", sizeof(c)); return 0; }
When I execute this, it says that size of "unsigned char" is "1" & size of "c" is "4". isn't that strange?
Not very. I know of systems where this program
would report both sizes as zero -- a good deal stranger,
don't you think?
(Hint: What is the type of the result of `sizeof',
and what is the type expected by the "%d" conversion?)
-- Er*********@sun .com
thanks but problem is not at malloc.
it must be,
printf("size of *c: %d\n", sizeof(*c));
In article <11************ **********@f14g 2000cwb.googleg roups.com>,
Parahat Melayev <pa*****@gmail. com> wrote: thanks but problem is not at malloc. it must be,
printf("size of *c: %d\n", sizeof(*c));
Glad to see you've solved your own problem. Congratulations !
Some minor nits...
Alexei A. Frounze wrote: "Parahat Melayev" <pa*****@gmail. com> wrote in message news:11******** **************@ g47g2000cwa.goo glegroups.com.. . #include <stdio.h> #include <stdlib.h> #include <limits.h>
int main() { unsigned char *c; c = malloc(sizeof(u nsigned char)); printf("size of unsigned char: %d\n", sizeof(unsigned char)); printf("size of c: %d\n", sizeof(c)); return 0; }
When I execute this, it says that size of "unsigned char" is "1" & size of "c" is "4". isn't that strange?
Nope. C isn't a char, it's a pointer (to a char).
No, C is a programming language (hint - case sensitivity!), and c is not a
pointer to a char, but a pointer to an unsigned char.
Usual stuff follows:
A) many people prefer a full prototype for main(), as in:
int main(void)
B) using the template p = malloc(n * sizeof *p), we could improve the malloc
to:
c = malloc(sizeof *c);
(ignoring n on this occasion, since we appear only to want one object).
C) sizeof yields a size_t, which is an unsigned integer type of unknown
size (in C90), so we will need to cast it. Unsigned longs are good
for this, so make that:
printf("size of unsigned char: %lu\n",
(unsigned long)sizeof(uns igned char));
(note that this is now required to write 1 on stdout), and
printf("size of c: %lu\n", (unsigned long)sizeof c);
Superfluous parentheses removed. Note the updated format specifiers.
Did I miss anything?
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
mail: rjh at above domain ra***********@g mail.com wrote: Parahat Melayev wrote: #include <stdio.h> #include <stdlib.h> #include <limits.h>
int main() { unsigned char *c; c = malloc(sizeof(u nsigned char)); printf("size of unsigned char: %d\n", sizeof(unsigned char)); printf("size of c: %d\n", sizeof(c)); return 0; }
When I execute this, it says that size of "unsigned char" is "1" & size of "c" is "4". isn't that strange?
what is c ???? c is the pointer which is going to hold the address which is of the char type.
malloc will return the address of the allocated memory. and so c holds the address, which is int.
The address is not int.
A pointer type is different from an int type.
--
pete
On 2005-07-15 09:24:30 -0500, "Parahat Melayev" <pa*****@gmail. com> said: #include <stdio.h> #include <stdlib.h> #include <limits.h>
int main() { unsigned char *c; c = malloc(sizeof(u nsigned char)); printf("size of unsigned char: %d\n", sizeof(unsigned char));
The size of an unsigned char is 1.
printf("size of c: %d\n", sizeof(c));
The size of a pointer is 4.
The size of the memory handled by the pointer is 1.
When I execute this, it says that size of "unsigned char" is "1" & size of "c" is "4". isn't that strange?
( gcc version 4.0.0 20050519 (Red Hat 4.0.0-8) )
I suggest reading a basic C book. You must know the difference between
a variable and a pointer.
PS. Sizes of vars and ptrs may vary on different platforms.
--
Sensei <se******@tin.i t>
cd /pub
more beer This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: F. GEIGER |
last post by:
When I start a py2exe-ed application I get the error
'ascii' codec can't encode character u'\xe9' in position 10: ordinal not in
range(128)
This is how I run py2exe:
setup.py py2exe -O1 --packages encodings
This is how the .po-file looks like:
|
by: Nadav |
last post by:
Hi,
I am tring to pass messages between threads, using the good old C++ I would call the GetMessage/PostThreadMessage APIs, Now, I am using C# and i can't find any equivalenty for these calls, any Idea how to communicate between threads and access the threads message queue will be appriciated...
--
Nadav
http://www.ddevel.com
|
by: Charles Law |
last post by:
Take a solution with a project hierarchy along the lines of an n-tier
system, so that we have a data layer, business layer and presentation layer.
The presentation layer is coupled to the business layer, and the business
layer is coupled to the data layer. So far so good.
Suppose the data layer raises an event, and it passes Me (the sender) as an
object, and e (MyEventArgs, a descendent of EventArgs) to the layer above
(the business...
|
by: kmounkhaty |
last post by:
Hi Guru,
My profiler trace does not display SP:CACHEMISS event, even thought I
drop store proc, clear both data cache and buffer cache but still does
not work.
Every thing works fine like: cachehit,
cacheinsert,cacheremove,executecontexthit etc...
Is there any special option that I need to turn it on?
|
by: jg |
last post by:
I setup a new windwos application project but I found out the sub main was
not called, I tried various form of Main (functions, subs) still no luck.
What did I miss?
Public Class SolverForm
Dim icnt_pieces = 0, iCurrent_Row = 0, iExpected_pieces = 16, i As
Integer
Dim ipb_piece() As PictureBox
Dim str_label() As String
Dim chr_Atrribute(iExpected_pieces)() As Char
| |
by: tjb |
last post by:
I often see code like this:
/// <summary>
/// Removes a node.
/// </summary>
/// <param name="node">The node to remove.</param>
public void RemoveNode(Node node) {
<...>
}
|
by: Useful Info |
last post by:
Like on 9/11, the Federal Government apparently WANTED people to die
at the hands of Cho at VA Tech, because they told campus police not to
pursue Cho after the double homicide occurred.
Story via
http://Muvy.org
|
by: anukedari |
last post by:
Hi,
Could any boby please help to get the answers for the following questions:
Is Apache always sends "X-Cache:MISS" header even when caching is off (disable)? or
Can we say that cache settings are enable if it sends "X-Cache:MISS" header in the response?
Your help would be appreciated.
|
by: Ram Prasad |
last post by:
I am trying to write a simple libspf2 plugin code for my postfix
( milter)
I am getting this unhelpful error message when I try to compile
gcc -g1 -Wall -I/usr/local/include/spf2 -I. -c mfunc.c
In file included from mfunc.c:1:
mfunc.c:42: error: expected ')' before '*' token
make: *** Error 1
my mfunc.c has on the line 42
|
by: manikandan |
last post by:
dont miss it just open
dont miss it just open
dont miss it just open
#############################
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |