Previous in Forum: VBA Code For Min. Cut-Set Matrix For Substation Busbar Reliability   Next in Forum: Has CAPTCHA Been Broken?
Close
Close
Close
15 comments
Rate Comments: Nested
Guru
Popular Science - Weaponology - New Member United Kingdom - Member - New Member

Join Date: May 2007
Location: Harlow England
Posts: 16512
Good Answers: 670

C Operators?

11/12/2013 11:00 AM

I'm getting increasing frustrated with tyring to work out how various C functions work (or don't) in the Std_Peripheral_Library for the processor I'm using.

There are things like.

lsifreqkhz >> 2U (where U has not been declared so is presumably not a variable)

and

AWU->APR

My C text book doesn't help as you can't find things like -> or >>2U in the index
Is C the most obscure, counterintuitive and downright idiotic language ever contrived?
{
Del;
}

BTW. I've solved assorted previous problems and got comms with my RFID module working... Just getting frustrated with the internal clock, which has a routine to 'calibrate' itself... yeah right... and nowhere do they give a tolerance for this internal 16Mhz clock (slaps furry head with paw)

__________________
health warning: These posts may contain traces of nut.
Register to Reply
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.
Guru

Join Date: Mar 2007
Location: by the beach in Florida
Posts: 33392
Good Answers: 1817
#1

Re: C Operators?

11/12/2013 11:50 AM
__________________
All living things seek to control their own destiny....this is the purpose of life
Register to Reply
Guru
Popular Science - Weaponology - New Member Netherlands - Member - New Member Fans of Old Computers - Commodore 64 - New Member

Join Date: Sep 2007
Location: Japan
Posts: 2703
Good Answers: 38
#2

Re: C Operators?

11/12/2013 7:56 PM

Maybe upgrade to C++ or C# for dummies?

__________________
From the Movie "The Big Lebowski" Don't pee on the carpet man!
Register to Reply
Guru

Join Date: Jan 2007
Location: Edinburgh, Bonnie Scotland
Posts: 1334
Good Answers: 23
#3

Re: C Operators?

11/13/2013 12:35 AM

>> bitwise shift

-> member selection

All Operators

__________________
Madness is all in the mind
Register to Reply
Guru
Popular Science - Weaponology - New Member United Kingdom - Member - New Member

Join Date: May 2007
Location: Harlow England
Posts: 16512
Good Answers: 670
#4
In reply to #3

Re: C Operators?

11/13/2013 2:56 AM

Thanks for your concise and sarcsam free response!

For those less helpful, I'd point out again it's easy to look up/google 'member selection' or 'shift operator' but searching for-> or >> doesn't work too well on google or in a text book with an index that says for 'Shift operator' 'see left shift operator or right shift operator'....

Cheezes, why can't they just put the damn page number??? I'm surprized that under 'left shift' it doesn't then say 'see shift operator'.


Del (in grumpy mode )

__________________
health warning: These posts may contain traces of nut.
Register to Reply
Guru
Popular Science - Weaponology - New Member United Kingdom - Member - New Member

Join Date: May 2007
Location: Harlow England
Posts: 16512
Good Answers: 670
#5
In reply to #4

Re: C Operators?

11/13/2013 3:19 AM

Actually I knew >> was a bit shift, I was more confused by the 2U ... From what I can glean the U just means that the '2' is unassigned? Who gives a toss? If it hasn't been declared as some variable or constant, do I giveadamn?... why they couldn't just divide by four in the first place? I would have made the code actually readable!
Grrrrrr ftzzzzz hissss.
Del

__________________
health warning: These posts may contain traces of nut.
Register to Reply
Guru

Join Date: Apr 2010
Location: About 4000 miles from the center of the earth (+/-100 mi)
Posts: 9910
Good Answers: 1141
#6

Re: C Operators?

11/13/2013 7:26 AM

I believe the U just tells the compiler to treat the constant 2 as an unsigned number. The compiler may require that you specify how constants are to be treated. The code just says to shift the value in Isifreakhz two places to the right.

Register to Reply
Guru
Popular Science - Weaponology - New Member United Kingdom - Member - New Member

Join Date: May 2007
Location: Harlow England
Posts: 16512
Good Answers: 670
#7
In reply to #6

Re: C Operators?

11/13/2013 8:19 AM

Cheers, that makes sense.
I get the impression that since I last used C about 15 years ago it has becom considerably worse.
Instead of encouraging modularity I've ended up lumping everything together to get it to work.

WTF is all this nonsense about having to define prototypes???
Total nonsense! A function already defines it's arguments... just 'cos the compilers are cr4p we are expected to define the arguments before the function as well!!!???

It's like going into the chip shop and saying:-

"I'm going to ask for cod and chips"
"Cod and chips please"!

I'm struggling to decipher, this self calibration routine that gives a 1 second interrupt every 800mS (slaps furry head with paw).
It has a slow running clock wich isn't very accurate, so it 'calibrates' off the faster master clock (16Mhz) which is of completely unspecified accuracy!!! (or at least I have yet to find figures for it in the 2^n data sheets, app notes, manuals etc which are downloadable and all of which have meaningless titles....

I'm sure I'll get there in the end... I just get the feeling it wouldn't have been any harder in assembler
Del

__________________
health warning: These posts may contain traces of nut.
Register to Reply
Guru

Join Date: Mar 2007
Location: by the beach in Florida
Posts: 33392
Good Answers: 1817
#8
In reply to #7

Re: C Operators?

11/13/2013 9:05 AM
__________________
All living things seek to control their own destiny....this is the purpose of life
Register to Reply
Guru
Popular Science - Weaponology - New Member United Kingdom - Member - New Member

Join Date: May 2007
Location: Harlow England
Posts: 16512
Good Answers: 670
#9
In reply to #8

Re: C Operators?

11/13/2013 9:35 AM

Ah.. got the damn timer running at close to 1second now...
It was just their 2 arrays of plug in values for the timebase and prescaler were wrong.

Still it only wasted half a day... and I do believe I get paid for this...or so they tell me.
Del

__________________
health warning: These posts may contain traces of nut.
Register to Reply
Guru

Join Date: Dec 2009
Posts: 581
Good Answers: 15
#10

Re: C Operators?

11/13/2013 4:06 PM

C is the best language evarr! :) It's like building a skyscraper when all you have is a rock to pound stuff with, water to mix stuff with and a match to melt/smelt stuff with. It's not that bad, much better than assembly language. And just try to program a device driver using Python or Perl...

Things like the 2U can cause really fun (read: outrageously subtle) bugs in some circumstances. Some operators will promote or demote a variable's data type to be consistent with the constant. It's unlikely that the U means diddly squat in this case, but if it was not flagged as unsigned, you could conceivably end up rotating your bits 2^16 - 2 times unexpectedly - assuming unsigned is what you want.

BTW, making you prototype your functions is just a best practice that was eventually coded into the standard. It's kind of like forcing a real engineer to use the same units of measure for their whole drawing.

__________________
Ignorance is no sin. Willful ignorance is unforgiveable.
Register to Reply
Guru

Join Date: Nov 2012
Posts: 633
Good Answers: 13
#11
In reply to #10

Re: C Operators?

11/13/2013 4:50 PM

Which compiler?

Register to Reply Off Topic (Score 5)
Guru
Popular Science - Weaponology - New Member United Kingdom - Member - New Member

Join Date: May 2007
Location: Harlow England
Posts: 16512
Good Answers: 670
#12

Re: C Operators?

11/13/2013 5:48 PM

Maybe I need a C++ book or something?... problem is I have no idea what specific flavour of C these routines are supposedly written in!
The program headers (in the Standard_peripheral_Library) just have the usual disclaimers and bull saying they don't promise it works etc etc...
It's written by ST who (like most other smanufacturers) have virtually no tech support these days execpt a forum where you ask questionsd and get no replies.
That's why I've asked on here... mind generally I've managed to work out roughly what's going on.

It just strikes me that 20 years ago module 'A' would quite happilly call a routine in module 'B'. Now it's hell's own job to get more than one module to link and compile.
I'm sure I'll get to grips with it all, but it seems unecessarilly complicated.
Classic example...
If you define a variable (say, Fred) outside a function it should be recognised as global.
Yet another module doesn't recognise Fred unless you tell it, that Fred is external! Why?
Again it's saying the samething twice! It's either global or it isn't! If it's not defined locally then, oooh let me think... I wonder if maybe it's defined as a global?...hardly rocket science for a compiler and linker.
Doubtless some smartar$e will say it's so you can have a global and a local variable with the same name... well that's just bonkers, bad programming and asking for trouble.


So, anyhow, now it's like going into the chip shop and saying.
"I'm going to ask for fish and chips"
"Specifically I'm going to ask for the globally recognised type of fish known as Cod"
"Can I have Cod and chips please?"

To which the chippy will say... sorry I don't understand, I Expected ; in line 1!

And that whole 2U thing is nonsense! A bit shift can only be an integer, you can't shift half a bit! If it was anything other than a decimal integer, I would specify it!
I think the U actually means it's not assigned a memory location, it's just a value... of course it's just a damn value!
If I wanted it stored I'd have given it a variable name and defined it!
There seems to scant logic there!
If I say Fred= Fred+3 I don't have to specify what I mean by 3
Where is the consistency? It seems to be complexity for the sake of it.

I feel I'm wasting time trying to understand the clinker/compiler and C rather than actually writing software!

Del

Damn I've exceeded my brevquot!)

(BTW. If you meant to ask me which compiler. Its by Raisonance)

__________________
health warning: These posts may contain traces of nut.
Register to Reply
Guru

Join Date: Nov 2012
Posts: 633
Good Answers: 13
#13
In reply to #12

Re: C Operators?

11/13/2013 6:13 PM

I'll lock for their doc's.....I was wondering about the best "evarr" I hate lib calls and the undocumented code that can be buried in them. I wish you well, and understand your frustration...good luck. gp

Register to Reply Off Topic (Score 5)
Guru

Join Date: Dec 2009
Posts: 581
Good Answers: 15
#14
In reply to #12

Re: C Operators?

11/13/2013 6:25 PM

Rixter is right, btw. 2U is unsigned as opposed to signed. Not that it makes a bit of difference with a shift operation. BUT, if the 2U shows up in a different expression, perhaps involving a floating point variable, then you need to consider that type promotion thing.

Don't go looking for C help in a C++ book. That will only drive you insane. Best to think of them as distinct languages.

Mostly, C is C. By "C" I mean, ANSI C.

__________________
Ignorance is no sin. Willful ignorance is unforgiveable.
Register to Reply
Guru
Popular Science - Weaponology - New Member Netherlands - Member - New Member Fans of Old Computers - Commodore 64 - New Member

Join Date: Sep 2007
Location: Japan
Posts: 2703
Good Answers: 38
#15
In reply to #12

Re: C Operators?

11/13/2013 7:58 PM

How about this one

__________________
From the Movie "The Big Lebowski" Don't pee on the carpet man!
Register to Reply
Register to Reply 15 comments
Copy to Clipboard

Users who posted comments:

Epke (2); geraldpaxton (2); GM1964 (1); Lynn.Wallace (2); Rixter (1); SolarEagle (2); user-deleted-1105 (5)

Previous in Forum: VBA Code For Min. Cut-Set Matrix For Substation Busbar Reliability   Next in Forum: Has CAPTCHA Been Broken?

Advertisement