function pointers

D

dhaval070

--=_Next_Part_DC5H7XFCZAIGQOTK
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

why the code in attachment does not work.


--=_Next_Part_DC5H7XFCZAIGQOTK
Content-Type: text/plain;
name="code.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="code.txt"

ZnVuY3Rpb24gZm9vKGludCBiKQ0Kew0KCXByaW50ZigiJWQiLGIpOw0KfQ0Kdm9pZCBtYWluKCkNCnsNCgl2b2lkKiAoZnB0ciopKGludCkgPSBmb287DQoJZnRwdHIoNSk7DQp9
--=_Next_Part_DC5H7XFCZAIGQOTK--
 
B

bitto1999

why the code in attachment does not work.

Besides syntax errors, there are lot of typo errors in this code.
[code.txt]function foo(int b)
{
printf("%d",b);}void main()
{
void* (fptr*)(int) = foo;
ftptr(5);

}


Try this:

#include <stdio.h>

void foo(int b)
{
printf("%d",b);
}

void main()
{
void (*ftptr)(int) = foo;
ftptr(5);
}
 
C

Cong Wang

why the code in attachment does not work.

Besides syntax errors, there are lot of typo errors in this code.
[code.txt]function foo(int b)
{
printf("%d",b);}void main()
{
void* (fptr*)(int) = foo;
ftptr(5);

}


Try this:

#include <stdio.h>

void foo(int b)
{
printf("%d",b);
}

void main()
{
void (*ftptr)(int) = foo;
ftptr(5);
}

Functin main() is int, not void.
 
C

Cong Wang

why the code in attachment does not work.

Besides syntax errors, there are lot of typo errors in this code.
[code.txt]function foo(int b)
{
printf("%d",b);}void main()
{
void* (fptr*)(int) = foo;
ftptr(5);

}


Try this:

#include <stdio.h>

void foo(int b)
{
printf("%d",b);
}

void main()
{
void (*ftptr)(int) = foo;
ftptr(5);
}

Function main() is int, not void.
 
K

Keith Thompson

--=_Next_Part_DC5H7XFCZAIGQOTK
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

why the code in attachment does not work.


--=_Next_Part_DC5H7XFCZAIGQOTK
Content-Type: text/plain;
name="code.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="code.txt"

ZnVuY3Rpb24gZm9vKGludCBiKQ0Kew0KCXByaW50ZigiJWQiLGIpOw0KfQ0Kdm9pZCBtYWluKCkNCnsNCgl2b2lkKiAoZnB0ciopKGludCkgPSBmb287DQoJZnRwdHIoNSk7DQp9
--=_Next_Part_DC5H7XFCZAIGQOTK--

I have no idea. If you want to post code, post it as plain text in
the body of your article, not as an attachment. (The above is what
your article looked like in my newsreader.)
 
R

Richard Heathfield

(e-mail address removed) said:
why the code in attachment does not work.

Why are you sending attachments to a text-only newsgroup?

Don't you realise how foolish that is?
 
M

Martin Ambuhl

Besides syntax errors, there are lot of typo errors in this code.

And a huge error that you duplicated:
Try this: [...]
void main()

Do *not* try that. Do *not* take advice from anyone who declares main
to have a void return type. Do *not* use any text that so advises.
 
R

Richard Heathfield

Martin Ambuhl said:
(e-mail address removed) wrote:
Try this: [...]
void main()

Do *not* try that. Do *not* take advice from anyone who declares main
to have a void return type.

....unless it is accompanied by a caveat that such a return type is required
by the freestanding implementation under discussion.
Do *not* use any text that so advises.

....unless it is documenting a freestanding implementation.
 
E

Eric Sosman

why the code in attachment does not work.



------------------------------------------------------------------------

function foo(int b)
{
printf("%d",b);
}
void main()
{
void* (fptr*)(int) = foo;
ftptr(5);
}

It works perfectly for me: The compiler spits out an
error message and refuses to run it, and that's exactly
as things should be. What problem are you having with it?
 
C

CBFalconer

why the code in attachment does not work.

Don't use attachments in newsgroups. Paste the code directly into
your article. The better newsservers will destroy any news article
containing an attachment.
 
D

David Wade

Richard Heathfield said:
(e-mail address removed) said:


Why are you sending attachments to a text-only newsgroup?

Don't you realise how foolish that is?

Marginally less foolish than answering the question without first getting
the content of the attachment extracted and posted in-line?
 
R

Richard Heathfield

David Wade said:
Marginally less foolish than answering the question without first getting
the content of the attachment extracted and posted in-line?

Nope. When he asks his question of code posted in line with newsgroup
conventions, I'll answer his code question. To accept his attachment
nonsense is to court future attachments, and so would be foolish.
 
R

Random832

2006-12-15 said:
David Wade said:


Nope. When he asks his question of code posted in line with newsgroup
conventions, I'll answer his code question. To accept his attachment
nonsense is to court future attachments, and so would be foolish.

And what do attachments have to do with being a text-only group or not,
anyway? As long as the attachments are text, I mean.
 
R

Richard

Random832 said:
And what do attachments have to do with being a text-only group or not,
anyway? As long as the attachments are text, I mean.

Ignore the pompous twit. He's not happy unless he's pouting about
"undefined behaviour".
 
K

Keith Thompson

Random832 said:
And what do attachments have to do with being a text-only group or not,
anyway? As long as the attachments are text, I mean.

We had this argument just a few months ago. Seach for subject "Should
attachments be accepted in comp.lang.c?", starting Aug 16, 2006. The
consensus then was that attachments, either text or binary, should be
discouraged.

As I mentioned in that earlier thread, my own newreader (Gnus) usually
handles attachments reasonably well, but in this most recent case I
only saw a bunch of encoded garbage. I don't know what made the
difference (and I'm not going to spend time figuring it out).
 
R

Richard Heathfield

Random832 said:
And what do attachments have to do with being a text-only group or not,
anyway? As long as the attachments are text, I mean.

Okay, I'll bite. Here is the attachment, arbitrarily broken to reduce line
length:

ZnVuY3Rpb24gZm9vKGludCBiKQ0Kew0KCXByaW50ZigiJWQiLGIpOw0KfQ0K
dm9pZCBtYWluKCkNCnsNCgl2b2lkKiAoZnB0ciopKGludCkgPSBmb287DQoJ
ZnRwdHIoNSk7DQp9

And the question is: why doesn't this code work? Well, let's put the
original unbroken line through a compiler:

foo.c:3: parse error at end of input

So there we have it - the code doesn't work because the compiler can't parse
it. And frankly, neither can I.
 
R

Richard Heathfield

Richard said:

Ignore the pompous twit. He's not happy unless he's pouting about
"undefined behaviour".

Actually, the pompous twit would far rather spend his time *not* pouting
about undefined behaviour. What you *can* do with C is far more interesting
than what you *can't* do with C.
 
C

CBFalconer

Random832 said:
And what do attachments have to do with being a text-only group
or not, anyway? As long as the attachments are text, I mean.

They weren't. The following is the attachment he provided:

--=_Next_Part_DC5H7XFCZAIGQOTK
Content-Type: text/plain;
name="code.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="code.txt"

ZnVuY3Rpb24gZm9vKGludCBiKQ0Kew0KCXByaW50ZigiJWQiLGIpOw0KfQ0Kdm9pZCBtYWluKCkNCnsNCgl2b2lkKiAoZnB0ciopKGludCkgPSBmb287DQoJZnRwdHIoNSk7DQp9
--=_Next_Part_DC5H7XFCZAIGQOTK--

It fails to compile here. One identifier, excessively long. No
semi-colon anywhere.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,068
Latest member
MakersCBDIngredients

Latest Threads

Top