 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Christian Kandeler Guest
|
Posted: Sat Jan 28, 2006 1:26 am Post subject: Re: Bit-fields and integral promotion/UACs |
|
|
Alex Fraser wrote:
| Quote: | The shift invokes undefined behaviour, because the left-hand operand has
signed type and the result cannot be represented in that type.
|
Don't you mean "cannot _necessarily_ be represented"? Surely if int is 32
bits, then 1 << 31 is okay? Or, more generally, 1 << sizeof int * CHAR_BIT
- 1 is? If not, I'd be interested to know why.
Christian |
|
| Back to top |
|
 |
Mara Guida Guest
|
Posted: Sat Jan 28, 2006 1:26 am Post subject: Re: Second Highest number in an array |
|
|
Joe Wright wrote:
| Quote: | #include <stdio.h
int main(void) {
int pri, sec, i, v;
|
int arr[] = {-4,-10,-3,-8,-6,-7,-2,-7,-9,-2,0}; /* Ah! Ah! */
| Quote: | pri = sec = 0;
for (i = 0; arr[i]; ++i) {
v = arr[i];
if (v > pri) sec = pri, pri = v;
if (v > sec && v < pri) sec = v;
}
printf("pri is %d, sec is %d\n", pri, sec);
return 0;
} |
|
|
| Back to top |
|
 |
Alex Fraser Guest
|
Posted: Sat Jan 28, 2006 2:38 am Post subject: Re: Bit-fields and integral promotion/UACs |
|
|
"CBFalconer" <cbfalconer (AT) yahoo (DOT) com> wrote in message
news:43DA301C.4EE5E4DC (AT) yahoo (DOT) com...
| Quote: | Alex Fraser wrote:
[snip]
Is my assumption correct that gcc 3 is wrong here?
By my understanding, yes.
Since you snipped the (faulty) code with added cast, it is hard to
criticize. Anyway I have added that (tautened) code back below:
#include <stdio.h
int main(void) {
struct test {
unsigned int x : 1;
} test;
test.x = 1;
printf("%lu\n", (unsigned long) ((unsigned int) test.x << 31));
return 0;
}
|
The OP stated 32-bit ints, so the value of "(unsinged int) text.x << 31" can
be represented in the result type, unsigned int.
Alex |
|
| Back to top |
|
 |
Ian Collins Guest
|
Posted: Sat Jan 28, 2006 2:38 am Post subject: Re: #include in header file for size_t |
|
|
Malcolm wrote:
| Quote: | "Keith Thompson" <kst-u (AT) mib (DOT) org> wrote .
Pedro Graca <hexkid (AT) dodgeit (DOT) com> writes:
Can this be an exception to the rule about not including header files in
header files?
Where did you get the idea that there's such a rule?
There's nothing wrong with including header files in header files.
Do it if you need to, don't do it if you don't.
I've never found a good answer to this one.
If you follow a policy of never allowing nested inclusions, then you have a
list of dependencies at the top of each source file.
You also have a list, in reverse order, of the files in call hierarchy.
The waters are muddied further when the compiler supports some form of |
pre-compiled headers, where a global header that includes all headers
can save a significant amount of compile time.
--
Ian Collins. |
|
| Back to top |
|
 |
Vladimir S. Oka Guest
|
Posted: Sat Jan 28, 2006 9:59 am Post subject: Re: Linux c app, called remotely by web. |
|
|
Ico wrote:
| Quote: | Vladimir S. Oka <novine (AT) btopenworld (DOT) com> wrote:
And as my fine ISP is playing its little tricks on me _again_, I
think I may never see that post -- ever... :-(
Check your reader settings, you might have plonked yourself. This
happened to me once, and it took me a quite some time to figure out
what was wrong.
|
Thanks for the advice, I'll have a look.
Although I don't think that's the problem. It's only roughly one in five
or so own posts that I can't see. Anyway, I'm getting used to it ,
and am keeping them in my outbox, just in case I have to reply to
someone with no quoting habits.
Cheers
Vladimir
--
Try to be the best of whatever you are, even if what you are is no
good. |
|
| Back to top |
|
 |
Vladimir S. Oka Guest
|
Posted: Sat Jan 28, 2006 12:14 pm Post subject: Re: Linux c app, called remotely by web. |
|
|
Michael Rasmussen wrote:
| Quote: | On Sat, 28 Jan 2006 09:59:37 +0000, Vladimir S. Oka wrote:
Although I don't think that's the problem. It's only roughly one in
five or so own posts that I can't see. Anyway, I'm getting used to it
, and am keeping them in my outbox, just in case I have to reply
to someone with no quoting habits.
What news reader do you use? Or are you posting via email?
|
KNode 0.9.2 (KDE 3.4.2 on SUSE 10.0 box).
If the question is about me saying `outbox`, I actually meant `Sent`
folder in KNode's `Local Folders` which is where everything that I post
ends up.
Cheers
Vladimir
--
Ask not for whom the <CONTROL-G> tolls. |
|
| Back to top |
|
 |
Vladimir S. Oka Guest
|
Posted: Sat Jan 28, 2006 1:34 pm Post subject: [OT] Problems with posting (was Re: Linux c app, called remo |
|
|
Michael Rasmussen wrote:
| Quote: | 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.
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).
Cheers
Vladimir |
|
| Back to top |
|
 |
junky_fellow@yahoo.co.in Guest
|
Posted: Sat Jan 28, 2006 1:50 pm Post subject: Re: advantage of using typedefs |
|
|
Emmanuel Delahaye wrote:
| Quote: | 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.
You will have this in C90:
typedef unsigned long biggest_int_t;
and that on C99:
typedef unsigned long long biggest_int_t;
With the help of some smart macros and #ifxxx directives, After a simple
recompile, the type will automagically be corrected after a simple
recompile of the project/lib or whatever.
|
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;
I believe unsigned long long should be highest possible integer type ?
Or am I wrong ?
Is there any other reason for doing that ? |
|
| Back to top |
|
 |
Ico Guest
|
Posted: Sat Jan 28, 2006 1:51 pm Post subject: Re: More Solutions |
|
|
Ico <usenet (AT) zevv (DOT) nl> 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 assume you forget the closing quote in the first printf(). Please make
sure that the code you post actually is correct and compiles.
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?
instead of for(k=0;k<j;k--) write for(k=0;k<j;j-- )
instead of for(k=0;k<j;k--) write for(k=0;k<j;j-- )
|
Ehm, no those are wrong ofcourse, I changed *and* inserted, which is
against the rules. I should sit on my hands before I type.
--
:wq
^X^Cy^K^X^C^C^C^C |
|
| Back to top |
|
 |
Ico Guest
|
Posted: Sat Jan 28, 2006 2:36 pm Post subject: Re: More Solutions |
|
|
Romram <sajjanharudit (AT) gmail (DOT) com> 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?
|
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.
Ico
--
:wq
^X^Cy^K^X^C^C^C^C |
|
| Back to top |
|
 |
Vladimir S. Oka Guest
|
Posted: Sat Jan 28, 2006 2:51 pm Post subject: [OT] Re: reda4win released |
|
|
pablo reda wrote:
| Quote: | mi program is plain c, gcc compiled with devcpp and SDL library
|
In the spirit of telling people what to do, not just what not to do:
This newsgroup, as well as comp.lang.misc, have English as their lingua
franca (most, if not all, of comp.* hierarchy does). So, advertising
stuff that's not in English, even if actually topical (which redaforth
is not here) and advertised in English, is not going to have much
impact.
So, provide a version of your home page in English, as well as at least
some documentation for your product.
Cheers
Vladimir
PS
Yes, I was sufficiently intrigued, but left your home page disappointed
and a feeling of having wasted time, as I couldn't understand a word of
it. NB, English is not my native language either.
--
Sooner or later you must pay for your sins. (Those who have already
paid may disregard this fortune). |
|
| Back to top |
|
 |
Michael Rasmussen Guest
|
Posted: Sat Jan 28, 2006 3:05 pm Post subject: Re: Linux c app, called remotely by web. |
|
|
On Sat, 28 Jan 2006 09:59:37 +0000, Vladimir S. Oka wrote:
| Quote: | Although I don't think that's the problem. It's only roughly one in five
or so own posts that I can't see. Anyway, I'm getting used to it , and
am keeping them in my outbox, just in case I have to reply to someone with
no quoting habits.
What news reader do you use? Or are you posting via email? |
--
Hilsen/Regards
Michael Rasmussen
http://keyserver.veridis.com:11371/pks/lookup?op=get&search=0xE3E80917 |
|
| Back to top |
|
 |
Mark McIntyre Guest
|
Posted: Sat Jan 28, 2006 3:05 pm Post subject: Re: advantage of using typedefs |
|
|
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)
| Quote: | 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.
| Quote: | 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
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
|
Posted: Sat Jan 28, 2006 3:05 pm Post subject: Re: Casting return value to fit within constraints of error |
|
|
On 27 Jan 2006 20:57:31 -0800, in comp.lang.c , "clayne"
<clayne (AT) anodized (DOT) com> wrote:
| Quote: | ssize_t read(int fildes, void *buf, size_t nbyte);
|
you /are/ aware that read() is offtopic here? Its a posix function,
probably best discussed in a unix group.
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
|
Posted: Sat Jan 28, 2006 3:05 pm Post subject: Re: embedded questions!!! |
|
|
On 27 Jan 2006 20:09:50 -0800, in comp.lang.c ,
bhanupratap.suraneni (AT) gmail (DOT) com wrote:
| Quote: | give the guide lines to learn about microcontrollers by self
|
The best guideline I can offer is to read the manual and other
documentation, and work through some code samples from other people in
your project team.
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 |
|
 |
Powered by phpBB © 2001, 2006 phpBB Group
|