C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help! Need to make my own color...
Goto page Previous  1, 2, 3, 4 ... 448, 449, 450  Next
 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C Language
View previous topic :: View next topic  
Author Message
Mark McIntyre
Guest





PostPosted: Sat Jan 28, 2006 3:06 pm    Post subject: Re: #include in header file for size_t Reply with quote



On Sat, 28 Jan 2006 00:55:14 +0000 (UTC), in comp.lang.c , "Malcolm"
<regniztar (AT) btinternet (DOT) com> wrote:
Quote:

However the world looks like this

typedef struct
{
INVADER *invaderlist;
int width;
int height;
CELL *cells;
SHIP *goody;
} WORLD;

So the easiest thing is to include the definitions of INVADER, CELL, and
SHIP as nested includes in world.h

I believe that since they're all pointers, you can actually declare
them as incomplete types, and only supply a definition when you need
it.


Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Back to top
Mark McIntyre
Guest





PostPosted: Sat Jan 28, 2006 3:06 pm    Post subject: Re: #include in header file for size_t Reply with quote



On 27 Jan 2006 20:19:24 -0800, in comp.lang.c , "clayne"
<clayne (AT) anodized (DOT) com> wrote:

Quote:
Malcolm wrote:
That means that every file in the program includes "world.h" and no other
headers, and any sense of hierarchy is lost.

I don't understand what hierarchy has to do with it here. Include when
you need a definition or declaration to be present - otherwise don't.

Malcolm's point was that one struct that is universally used, relies
on pointers to other structs which are not always used. Thus his
universal header included all other headers and there was no easy way
to tell what features a given module actually used.

I actually think he can get round this via incomplete types, but its a
valid issue.

Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Back to top
Michael Rasmussen
Guest





PostPosted: Sat Jan 28, 2006 3:06 pm    Post subject: Re: Linux c app, called remotely by web. Reply with quote



On Sat, 28 Jan 2006 12:14:20 +0000, Vladimir S. Oka wrote:

Quote:

KNode 0.9.2 (KDE 3.4.2 on SUSE 10.0 box).
I have not heard of any such problems with KNode. Have you filed it as a

bug?
--
Hilsen/Regards
Michael Rasmussen
http://keyserver.veridis.com:11371/pks/lookup?op=get&search=0xE3E80917
Back to top
Vladimir S. Oka
Guest





PostPosted: Sat Jan 28, 2006 3:24 pm    Post subject: Re: [OT] Problems with posting (was Re: Linux c app, called Reply with quote

CBFalconer wrote:

Quote:
"Vladimir S. Oka" wrote:

I don't actually think the problem's with KNode. Here's what
actually happens:
snip
Bugging your ISP is probably the only way. It looks as if he is
failing to post articles originating on his system. When he
propagates them to other systems they are marked as "SEEN-BY" his
system, so they don't come back.


It seems to have been KNode after all. I tried Thunderbird and it
happily showed all my posts. Went back to KNode, unsubscribed to c.l.c,
exit, re-subscribed, and voila, here's everything again. I tried this
as I had this un/re-sub procedure nagging at the back of my head for a
while, as if I saw it in a post recently. Time to talk to KNode people,
then.

Thanks again for help and advice.

Cheers

Vladimir
Back to top
Joe Wright
Guest





PostPosted: Sat Jan 28, 2006 4:01 pm    Post subject: Re: More Solutions Reply with quote

Romram wrote:
Quote:
I was asked to submit atleast 5 solutions for the following problem:

By Replacing/Adding or deleting only one character from the following
code snippet, make it print tttttttttttttttttttt (20 times)

#include<stdio.h

int main()
{
int k, j=20;
for(k=0;k<j;k--)
printf("t);
printf("\n");
return 0;
}

I came up with 3 solutions which were

1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--)

2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--)

3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)

Can anyone suggest me 2 more solutions?


Clearly some sort of homework. The canonical for loop ..

for (k = 0; k < j; ++k)

... otherwise the loop almost infinite. The snippet is broken in at least
two places and cannot be fixed with one change (as far as I can tell).

Please compile these things into small programs before posting here.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Back to top
Thad Smith
Guest





PostPosted: Sat Jan 28, 2006 4:01 pm    Post subject: Re: advantage of using typedefs Reply with quote

junky_fellow (AT) yahoo (DOT) co.in wrote:
Quote:
Emmanuel Delahaye wrote:

junky_fellow (AT) yahoo (DOT) co.in a écrit :

I wanted to know what advantage do we get by typedefs ? Why we did not
declare
offset simply as
long off_t;

It's often a portability issue. Imagine you want a type that hold the
biggest possible unsigned integer.

That is one good reason. I often define types for another: I create my
own conceptual data type, which I document where the typedef occurs.
For example:

typedef unsigned long ticks; /* elapsed time, unit = 16 us. */
....
ticks pulseWidth; /* width of last pulse */
ticks pulseInterval; /* time between last 2 pulses */
void DelayTicks (ticks delay);

Here using ticks carries with it the type of data and the scaling.

--
Thad
Back to top
CBFalconer
Guest





PostPosted: Sat Jan 28, 2006 4:01 pm    Post subject: Re: [OT] Problems with posting (was Re: Linux c app, called Reply with quote

"Vladimir S. Oka" wrote:
Quote:

I don't actually think the problem's with KNode. Here's what
actually happens:

I post a follow-up to an article on c.l.c using my ISP's news
server. Most of the time I see it on c.l.c in due time on my
ISP's news server. Sometimes, however, I never see it on c.l.c
on my ISP's news servers. However, it's /always/ visible on
Google Groups, or if I subscribe to c.l.c using a different
news servers (say, one of the free ones). All the while I'm
using same news client, i.e. KNode.

I'll drop it here now, as it's off topic. Any suggestions
where's the best place to ask (apart for bugging my ISP, of
course).

Bugging your ISP is probably the only way. It looks as if he is
failing to post articles originating on his system. When he
propagates them to other systems they are marked as "SEEN-BY" his
system, so they don't come back.

--
"The power of the Executive to cast a man into prison without
formulating any charge known to the law, and particularly to
deny him the judgement of his peers, is in the highest degree
odious and is the foundation of all totalitarian government
whether Nazi or Communist." -- W. Churchill, Nov 21, 1943
Back to top
Michael Rasmussen
Guest





PostPosted: Sat Jan 28, 2006 4:01 pm    Post subject: Re: [OT] Problems with posting (was Re: Linux c app, called Reply with quote

On Sat, 28 Jan 2006 13:34:00 +0000, Vladimir S. Oka wrote:

Quote:
Michael Rasmussen wrote:

On Sat, 28 Jan 2006 12:14:20 +0000, Vladimir S. Oka wrote:


KNode 0.9.2 (KDE 3.4.2 on SUSE 10.0 box).
I have not heard of any such problems with KNode. Have you filed it as a
bug?

I don't actually think the problem's with KNode. Here's what actually
happens:

I post a follow-up to an article on c.l.c using my ISP's news server. Most
of the time I see it on c.l.c in due time on my ISP's news server.
Sometimes, however, I never see it on c.l.c on my ISP's news servers.
However, it's /always/ visible on Google Groups, or if I subscribe to
c.l.c using a different news servers (say, one of the free ones). All the
while I'm using same news client, i.e. KNode.

Try see if the problems occurs in another news reader. If not
I'll drop it here now, as it's off topic. Any suggestions where's the best
place to ask (apart for bugging my ISP, of course).
Try KDE mail lists.

--
Hilsen/Regards
Michael Rasmussen
http://keyserver.veridis.com:11371/pks/lookup?op=get&search=0xE3E80917
Back to top
William J. Leary Jr.
Guest





PostPosted: Sat Jan 28, 2006 5:00 pm    Post subject: Re: advantage of using typedefs Reply with quote

"Thad Smith" <ThadSmith (AT) acm (DOT) org> wrote in message
news:43db9067$0$81213$892e0abb (AT) auth (DOT) newsreader.octanews.com...
Quote:
junky_fellow (AT) yahoo (DOT) co.in wrote:
It's often a portability issue. Imagine you want a type that hold the
biggest possible unsigned integer.

That is one good reason. I often define types for another: I create my
own conceptual data type, which I document where the typedef occurs.
For example:

typedef unsigned long ticks; /* elapsed time, unit = 16 us. */
...
ticks pulseWidth; /* width of last pulse */
ticks pulseInterval; /* time between last 2 pulses */
void DelayTicks (ticks delay);

Here using ticks carries with it the type of data and the scaling.

From a tools perspective, this can be quite powerful. I've picked up
development on a project where the former developer used typedefs just as
you've done above. One of the advantages is that when I encounter one of his
typedef'd items, I can do a right-click on it and one of the menu options is
"show typedef" which, when selected, shows the typedef, in context. Thus, I
can immediately tell what he meant the variable or argument to hold or
represent. Very handy, and saves a pile of time. Even in the older system
where I have to find them using grep, it still means that once I've found it,
the comments on what it means are right there.

- Bill
Back to top
Pedro Graca
Guest





PostPosted: Sat Jan 28, 2006 5:00 pm    Post subject: Re: More Solutions Reply with quote

Ico wrote:
Quote:
Romram <sajjanharudit (AT) gmail (DOT) com> wrote:
I was asked to submit atleast 5 solutions for the following problem:

By Replacing/Adding or deleting only one character from the following
code snippet, make it print tttttttttttttttttttt (20 times)

#include<stdio.h

int main()
{
int k, j=20;
for(k=0;k<j;k--)
printf("t);
printf("\n");
return 0;
}

I came up with 3 solutions which were

1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--)
2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--)
3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)

Can anyone suggest me 2 more solutions?

I have reason to believe you have already found the only three possible
solutions. I couldn't think of any more than the ones you already
stated, so I have just tried a brute-force search of all possible
replaces/additions/deletions of all possible characters at all possible
locations.

I'm interested in any other solutions that I might have missed.

add a single `-' to for(k=0;k<j;k--): for(k=0;-k<j;k--)
________^________
--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Back to top
Ico
Guest





PostPosted: Sat Jan 28, 2006 6:00 pm    Post subject: Re: More Solutions Reply with quote

Pedro Graca <hexkid (AT) dodgeit (DOT) com> wrote:
Quote:
Ico wrote:
Romram <sajjanharudit (AT) gmail (DOT) com> wrote:
I was asked to submit atleast 5 solutions for the following problem:

By Replacing/Adding or deleting only one character from the following
code snippet, make it print tttttttttttttttttttt (20 times)

#include<stdio.h

int main()
{
int k, j=20;
for(k=0;k<j;k--)
printf("t);
printf("\n");
return 0;
}

I came up with 3 solutions which were

1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--)
2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--)
3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)

Can anyone suggest me 2 more solutions?

I have reason to believe you have already found the only three possible
solutions. I couldn't think of any more than the ones you already
stated, so I have just tried a brute-force search of all possible
replaces/additions/deletions of all possible characters at all possible
locations.

I'm interested in any other solutions that I might have missed.

add a single `-' to for(k=0;k<j;k--): for(k=0;-k<j;k--)
________^________

Is that not the same as OP's solution #2 ?

--
:wq
^X^Cy^K^X^C^C^C^C
Back to top
Pedro Graca
Guest





PostPosted: Sat Jan 28, 2006 7:00 pm    Post subject: Re: More Solutions Reply with quote

Ico wrote:
Quote:
Romram <sajjanharudit (AT) gmail (DOT) com> wrote:
I was asked to submit atleast 5 solutions for the following problem:

By Replacing/Adding or deleting only one character from the following
code snippet, make it print tttttttttttttttttttt (20 times)

#include<stdio.h

int main()
{
int k, j=20;
for(k=0;k<j;k--)
printf("t);
printf("\n");
return 0;
}

I came up with 3 solutions which were

1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--)
2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--)
3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)

Can anyone suggest me 2 more solutions?

I have reason to believe you have already found the only three possible
solutions. I couldn't think of any more than the ones you already
stated, so I have just tried a brute-force search of all possible
replaces/additions/deletions of all possible characters at all possible
locations.

I'm interested in any other solutions that I might have missed.

My last post was a repeated solution. Sorry.


If you don't mind UB (decrementing k past INT_MIN) or using an
unprototyped function or waiting for the program to go through all the
negative values of the int type ...

instead of printf("t"); write pruntf("t"); and link with a library that
defines

int pruntf(char const * t) {
static int n = 20;
if (n) {
--n;
printf("%s", t);
}
return 0;
}


--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Back to top
Romram
Guest





PostPosted: Sat Jan 28, 2006 8:00 pm    Post subject: Re: More Solutions Reply with quote

Quote:
instead of printf("t"); write pruntf("t"); and link with a library that
defines

int pruntf(char const * t) {
static int n = 20;
if (n) {
--n;
printf("%s", t);
}
return 0;
}



You can change only one character in the code..... adding a library is
way out of the question..
Back to top
Keith Thompson
Guest





PostPosted: Sat Jan 28, 2006 8:00 pm    Post subject: Re: advantage of using typedefs Reply with quote

Mark McIntyre <markmcintyre (AT) spamcop (DOT) net> writes:
Quote:
On 28 Jan 2006 00:50:55 -0800, in comp.lang.c ,
"junky_fellow (AT) yahoo (DOT) co.in" <junky_fellow (AT) yahoo (DOT) co.in> wrote:

(concerning typdef'ing)

Thanx for your reply, Emmanuel. But if this is the case (ie we need
the biggest possible unsigned integer to hold offset ) then why not declare
unsigned long long offset;

Because then its size would vary from platform to platform, and on a
c90 implementation it would be an error. Some implementations spell
"long long" as "__int64", others don't support it at all etc etc.

I believe unsigned long long should be highest possible integer type ?
Or am I wrong ?

You're right, but the size of long long varies from platform to
platform

Yes, but if you want the biggest unsigned integer type, you have to
accept that its size is going to vary.

If you want a type whose size *doesn't* vary, you want
something like uint64_t (and if you need this in C90, see
<http://www.lysator.liu.se/c/q8/>). (I think most C90 implementations
these days provide 64-bit integer types under some name.)

BTW, C99 defines uintmax_t for precisely this purpose.

--
Keith Thompson (The_Other_Keith) kst-u (AT) mib (DOT) 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.
Back to top
Mark McIntyre
Guest





PostPosted: Sat Jan 28, 2006 9:00 pm    Post subject: Re: advantage of using typedefs Reply with quote

On Sat, 28 Jan 2006 19:32:56 GMT, in comp.lang.c , Keith Thompson
<kst-u (AT) mib (DOT) org> wrote:

Quote:
Mark McIntyre <markmcintyre (AT) spamcop (DOT) net> writes:
On 28 Jan 2006 00:50:55 -0800, in comp.lang.c ,
"junky_fellow (AT) yahoo (DOT) co.in" <junky_fellow (AT) yahoo (DOT) co.in> wrote:

I believe unsigned long long should be highest possible integer type ?
Or am I wrong ?

You're right, but the size of long long varies from platform to
platform

Yes, but if you want the biggest unsigned integer type, you have to
accept that its size is going to vary.

.... which was my point.

Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Back to top
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C Language All times are GMT
Goto page Previous  1, 2, 3, 4 ... 448, 449, 450  Next
Page 3 of 450

 
 


Powered by phpBB © 2001, 2006 phpBB Group