•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 427,100 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,273 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 748 | Replies: 23
![]() |
•
•
Join Date: Jul 2008
Posts: 11
Reputation:
Rep Power: 1
Solved Threads: 0
following is a simple embedded c piece of code, can somebody tell me is there a problem in it ?
i am new to embedded programming. It will be great help, any pointers to this ...
thanks
pdk
c Syntax (Toggle Plain Text)
boolean new(int a) { return !(a & 7); }
thanks
pdk
Last edited by Narue : Jul 12th, 2008 at 8:44 am. Reason: Added code tags
>can somebody tell me is there a problem in it ?
Assuming boolean is a typedef, there's nothing syntactically or semantically wrong with that function. Perhaps if you told us what it's supposed to do, we can tell you if it actually does it.
Assuming boolean is a typedef, there's nothing syntactically or semantically wrong with that function. Perhaps if you told us what it's supposed to do, we can tell you if it actually does it.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Your analysis is correct.
But whether there is anything 'wrong' depends on what it's supposed to do.
If for example is was a test to see if a number was >= 8, then it would fail miserably on negative numbers.
The name 'new' certainly doesn't help.
But whether there is anything 'wrong' depends on what it's supposed to do.
If for example is was a test to see if a number was >= 8, then it would fail miserably on negative numbers.
The name 'new' certainly doesn't help.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
True.
So what's the indented function then?
If we don't know what it's supposed to do, how can we say whether it's right or wrong?
So what's the indented function then?
If we don't know what it's supposed to do, how can we say whether it's right or wrong?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
•
•
Join Date: Jul 2008
Posts: 11
Reputation:
Rep Power: 1
Solved Threads: 0
even i was not sure. because in the test, i was supposed to tell what the function is intended to do and any potential problems !!!.
i could not exactly figure out this .. i.e why any pointers to this will be helpful.
as pointed out, i was also thinking whether it will cause any problems for -ve numbers .. but without any potential soln..
i could not exactly figure out this .. i.e why any pointers to this will be helpful.
as pointed out, i was also thinking whether it will cause any problems for -ve numbers .. but without any potential soln..
•
•
Join Date: Jul 2008
Posts: 11
Reputation:
Rep Power: 1
Solved Threads: 0
This function resave number, if the number is 0 its return true else its return false.
The Boolean " a & 7 ;" says if a != 0 and 7 != 0 then 1 else 0
Has you see the 7 is not needed
--------------------------------
when the number is lets say '8'. it still returns '1' .. i.e basically numbers for which lsb 3 bits are not set. it will return '1'
The Boolean " a & 7 ;" says if a != 0 and 7 != 0 then 1 else 0
Has you see the 7 is not needed
--------------------------------
when the number is lets say '8'. it still returns '1' .. i.e basically numbers for which lsb 3 bits are not set. it will return '1'
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the C Forum
- Previous Thread: Return values from functions
- Next Thread: Read from data file at some specified location



Linear Mode