Connecting Tech Pros Worldwide Forums | Help | Site Map

Use of diff pointers

Comp.Lang.c
Guest
 
Posts: n/a
#1: May 20 '06
Hello
Iam Niranjan... i have one small doubt.

void main()
{
int size;
size = sizeof(int *);
printf("\n size of int *------>%x"size);
size = sizeof(char *);
printf("\n size of char *------>%x"size);
size = sizeof(float *);
printf("\n size of float *------>%x"size);
}
here i got the same size for all three.
when all three taking the same size... why we need different type of
pointers..
plz clarify any one..
Thanking you
Niranjan


Richard Heathfield
Guest
 
Posts: n/a
#2: May 20 '06

re: Use of diff pointers


Comp.Lang.c said:
[color=blue]
> Hello
> Iam Niranjan... i have one small doubt.
>
> void main()[/color]

Lesson 1: main returns int, not void.

When you have absorbed that lesson, let us know.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Comp.Lang.c
Guest
 
Posts: n/a
#3: May 20 '06

re: Use of diff pointers


whats the relation between main return type & pointers size...?

Richard Heathfield
Guest
 
Posts: n/a
#4: May 20 '06

re: Use of diff pointers


Comp.Lang.c said:
[color=blue]
> whats the relation between main return type & pointers size...?[/color]

None whatsoever, because main always returns int.

When you understand that, we can move on to the next error in your example
program. There doesn't seem to be any point in teaching you new things
until you've understood the old things correctly. It would be like building
a house on sand.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Keith Thompson
Guest
 
Posts: n/a
#5: May 20 '06

re: Use of diff pointers


"Comp.Lang.c" <podduturiniranjan@gmail.com> writes:[color=blue]
> Iam Niranjan... i have one small doubt.[/color]

I suggest you pick a name for yourself other than "Comp.Lang.c".
That's the name of the newsgroup; referring to yourself by the same
name is bound to cause confusion. (Using your own real name is
usually best, but some people choose to use pseudonyms.)
[color=blue]
> void main()[/color]

int main(void)
[color=blue]
> {
> int size;
> size = sizeof(int *);
> printf("\n size of int *------>%x"size);
> size = sizeof(char *);
> printf("\n size of char *------>%x"size);
> size = sizeof(float *);
> printf("\n size of float *------>%x"size);
> }
> here i got the same size for all three.
> when all three taking the same size... why we need different type of
> pointers..[/color]

Because they point to different types.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Typhonike
Guest
 
Posts: n/a
#6: May 20 '06

re: Use of diff pointers


they have fixed in size because pointer do not hold the variable's
itself they only hold the adresses.But it do not mean that one type of
pointer can hold all the types.we have to tell the compiler "this
pointer is use for this type of variable".the reason is c uses STRONGLY
TYPE CHECKING.we can't change variables types(of course pointers are
variavles too) during the run time and compile time.

Comp.Lang.c
Guest
 
Posts: n/a
#7: May 20 '06

re: Use of diff pointers


Thanq Mr Keith Thompson.
its very very nice meeting you.
Thanking you, for your great Help.
Niranjan Podduturi.
+919849238297

Comp.Lang.c
Guest
 
Posts: n/a
#8: May 20 '06

re: Use of diff pointers


Hello Sir,
I know ...
void main returns int.
Iam niranjan podduturi.
Iam from Hyderabad/India
Thanking you Sir.
Niranjan Podduturi

Richard Heathfield
Guest
 
Posts: n/a
#9: May 20 '06

re: Use of diff pointers


Comp.Lang.c said:
[color=blue]
> Hello Sir,
> I know ...
> void main returns int.[/color]

No, main returns int.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
pete
Guest
 
Posts: n/a
#10: May 20 '06

re: Use of diff pointers


Typhonike wrote:[color=blue]
>
> they have fixed in size because pointer do not hold the variable's
> itself they only hold the adresses.[/color]

No.

sizeof(int *), sizeof(char *), and sizeof(float *)
are all equal on OP's implementation through sheer coincidence.

The relative sizes of those types of pointers
is unspecified by the rules of the C programming language.

--
pete
Roberto Waltman
Guest
 
Posts: n/a
#11: May 20 '06

re: Use of diff pointers


On 19 May 2006 23:25:50 -0700, "Comp.Lang.c"
<podduturiniranjan@gmail.com> wrote:
[color=blue]
>Hello
>Iam Niranjan... i have one small doubt.
>
>void main()
>{
>int size;
>size = sizeof(int *);
>printf("\n size of int *------>%x"size);
>size = sizeof(char *);
>printf("\n size of char *------>%x"size);
>size = sizeof(float *);
>printf("\n size of float *------>%x"size);
>}
>here i got the same size for all three.
>when all three taking the same size... why we need different type of
>pointers..
>plz clarify any one..
>Thanking you
>Niranjan[/color]

Try the following:

#include <stdio.h>
#include <stdlib.h>

int main()
{
int size;
int *p_to_int;
char *p_to_char;
short *p_to_short;
float *p_to_float;

size = sizeof(int *);
printf("size of int * ------->%x\n", size);

size = sizeof(char *);
printf("size of char * ------->%x\n", size);

size = sizeof(short *);
printf("size of short * ------>%x\n", size);

size = sizeof(float *);
printf("size of float * ------>%x\n", size);

size = sizeof(*p_to_int);
printf("size of *p_to_int ------>%x\n", size);

size = sizeof(*p_to_char);
printf("size of *p_to_char ------>%x\n", size);

size = sizeof(*p_to_short);
printf("size of *p_to_short ------>%x\n", size);

size = sizeof(*p_to_float);
printf("size of *p_to_float ------>%x\n", size);

return EXIT_SUCCESS;
}
Roberto Waltman
Guest
 
Posts: n/a
#12: May 20 '06

re: Use of diff pointers


Roberto Waltman <usenet@rwaltman.net> wrote:[color=blue]
><podduturiniranjan@gmail.com> wrote:[color=green]
>>here i got the same size for all three.
>>when all three taking the same size... why we need different type of
>>pointers..
>>plz clarify any one..
>>Thanking you
>>Niranjan[/color]
>
>Try the following:[/color]

Sorry, pasted the wrong file. I meant, try the following:

#include <stdio.h>
#include <stdlib.h>

int main()
{
int size;
char *p_to_char;
short *p_to_short;
int *p_to_int;
float *p_to_float;
double *p_to_double;

size = sizeof(p_to_char);
printf("size of p_to_char ------>%x\n", size);

size = sizeof(*p_to_char);
printf("size of *p_to_char ------>%x\n", size);

size = sizeof(p_to_short);
printf("size of p_to_short ------>%x\n", size);

size = sizeof(*p_to_short);
printf("size of *p_to_short ------>%x\n", size);

size = sizeof(p_to_int);
printf("size of p_to_int ------>%x\n", size);

size = sizeof(*p_to_int);
printf("size of *p_to_int ------>%x\n", size);

size = sizeof(p_to_float);
printf("size of p_to_float ------>%x\n", size);

size = sizeof(*p_to_float);
printf("size of *p_to_float ------>%x\n", size);

size = sizeof(p_to_double);
printf("size of p_to_double ------>%x\n", size);

size = sizeof(*p_to_double);
printf("size of *p_to_double ------>%x\n", size);

return EXIT_SUCCESS;
}

santosh
Guest
 
Posts: n/a
#13: May 21 '06

re: Use of diff pointers


Comp.Lang.c wrote:[color=blue]
> Hello Sir,
> I know ...
> void main returns int.
> Iam niranjan podduturi.
> Iam from Hyderabad/India
> Thanking you Sir.
> Niranjan Podduturi[/color]

I suppose you're another one of the frustrated BPO f**kers, trying to
troll on Usenet defaming your own country.

Go get a life. All you're managing to do is to appear a complete
jackass.

santosh
Guest
 
Posts: n/a
#14: May 21 '06

re: Use of diff pointers


Typhonike wrote:[color=blue]
> they have fixed in size because pointer do not hold the variable's
> itself they only hold the adresses.[/color]

<OT>
Address sizes aren't fixed on all hardware. For example varying pointer
types were used under the real-mode x86 CPU, because of it's
segment:offset nature of memory addressing. The pointer sizes are the
same for the OP only because of his implementation. Though the OP
didn't mention it, it's very likely that his platform is a 32-bit x86
running under a protected mode OS with a 32-bit flat memory model. In
this case a single GP register can access the full range of a program's
address space and hence the C pointer types are constant in size.

The C standard does not specify the particular size or structure of
pointers. It's upto the implementor, who is in turn, dictated by the
nature of the hardware.
</OT>

Default User
Guest
 
Posts: n/a
#15: May 21 '06

re: Use of diff pointers


Comp.Lang.c wrote:
[color=blue]
> Hello Sir,
> I know ...
> void main returns int.[/color]

Please read the information below.



Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
santosh
Guest
 
Posts: n/a
#16: May 21 '06

re: Use of diff pointers


Comp.Lang.c wrote:[color=blue]
> Hello Sir,
> I know ...[/color]

Quote context if you're serious about participating in this newsgroup.
Read the following:

<http://cfaj.freeshell.org/google/>
<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>
<http://www.safalra.com/special/googlegroupsreply/>
<http://en.wikipedia.org/wiki/USENET>
[color=blue]
> void main returns int.[/color]

Under a conforming implementation main() returns an int and only an int
at all times. void main() is invalid.
[color=blue]
> Iam niranjan podduturi.
> Iam from Hyderabad/India[/color]

Who the hell cares what you're name is or where you stay. Confine your
posts to this group to ISO C.
[color=blue]
> Thanking you Sir.
> Niranjan Podduturi[/color]

BTW, Usenet posts aren't letters.

Keith Thompson
Guest
 
Posts: n/a
#17: May 21 '06

re: Use of diff pointers


"santosh" <santosh.k83@gmail.com> writes:[color=blue]
> Comp.Lang.c wrote:[color=green]
>> Hello Sir,
>> I know ...[/color]
>
> Quote context if you're serious about participating in this newsgroup.
> Read the following:
>
> <http://cfaj.freeshell.org/google/>
> <http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>
> <http://www.safalra.com/special/googlegroupsreply/>
> <http://en.wikipedia.org/wiki/USENET>
>[color=green]
>> void main returns int.[/color]
>
> Under a conforming implementation main() returns an int and only an int
> at all times. void main() is invalid.[/color]

That's not *quite* true. The standard allows an implementation to
define other forms for main(), but only
int main(void)
and
int main(int argc, char **argv)
are guaranteed to be portable (for hosted implementations), and
there's practically never a good reason to use void main().
[color=blue][color=green]
>> Iam niranjan podduturi.
>> Iam from Hyderabad/India[/color]
>
> Who the hell cares what you're name is or where you stay. Confine your
> posts to this group to ISO C.[/color]

Perhaps you could have expressed this with a bit more subtlety. The
OP needs to learn a few things about this newsgroup, and about Usenet
in general, but there's no need to be rude about it.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Tomás
Guest
 
Posts: n/a
#18: May 21 '06

re: Use of diff pointers


Keith Thompson posted:
[color=blue]
> That's not *quite* true. The standard allows an implementation to
> define other forms for main(), but only
> int main(void)[/color]


We're getting into semantics here, but I don't consider:

int main()

to be different from:

int main(void)


Nor do I consider any of the following to be different:

signed main();
signed int main(void);
int main();
signed main(void);
signed int main();
int main(void);


-Tomás
Keith Thompson
Guest
 
Posts: n/a
#19: May 21 '06

re: Use of diff pointers


"Tomás" <No.Email@Address> writes:[color=blue]
> Keith Thompson posted:
>[color=green]
>> That's not *quite* true. The standard allows an implementation to
>> define other forms for main(), but only
>> int main(void)[/color]
>
>
> We're getting into semantics here, but I don't consider:
>
> int main()
>
> to be different from:
>
> int main(void)[/color]

They're different in a declaration (prototype), but the same in a
definition. But then, there's not much point in declaring a separate
prototype for main.
[color=blue]
> Nor do I consider any of the following to be different:
>
> signed main();
> signed int main(void);
> int main();
> signed main(void);
> signed int main();
> int main(void);[/color]

Right. I should have added the phrase "or equivalent". For example:

typedef int FOOBAR;
typedef char OCELOT;
FOOBAR main(FOOBAR lutefisk, OCELOT **uffda);

is also legal.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dik T. Winter
Guest
 
Posts: n/a
#20: May 21 '06

re: Use of diff pointers


In article <b%Obg.9386$j7.305828@news.indigo.ie> "Tomás" <No.Email@Address> writes:
....[color=blue]
> We're getting into semantics here, but I don't consider:
> int main()
> to be different from:
> int main(void)[/color]

Eh? See the difference when I write
a = main(1, 2);
this is valid for "int main()" but not for "int main(void)".
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
pete
Guest
 
Posts: n/a
#21: May 21 '06

re: Use of diff pointers


Tomás wrote:
[color=blue]
> We're getting into semantics here, but I don't consider:
>
> int main()
>
> to be different from:
>
> int main(void)[/color]

In C, the first of those two,
is an obsolescent form and the second one isn't.

ISO/IEC 9899: 1990

6.9.4 Function declarators
The use of function declarators with empty parentheses
(not prototype-format parameter type declarators)
is an obsolescent feature.

--
pete
Old Wolf
Guest
 
Posts: n/a
#22: May 21 '06

re: Use of diff pointers


Tomás wrote:[color=blue]
>
> signed main();[/color]

Hi JKop!

Closed Thread