LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-28-2006, 12:28 PM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Rep: Reputation: 45
c code?


What the following lines do?
uint16 t l e d s = count e r >> 4 ;



count e r = (messageˇ>s t r eng th + 60) & 0 x f f ;
 
Old 04-28-2006, 12:43 PM   #2
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
is the spacing and spelling correct?
 
Old 04-28-2006, 01:00 PM   #3
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
i think so i have copy and pasted text here from a friend that need help
 
Old 04-28-2006, 01:04 PM   #4
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
hmm..

iv never done c, but i know intermediate c++ and advanced java.

if i were to guess, i would say that the code would do nothing because it isnt typed properly.

is there more code we could see, or can you verify this is the exact code (spacing and all) that works?
 
Old 04-28-2006, 01:16 PM   #5
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
Ok forget the mispelled text.. just think its an elgorithm written in c/c++
 
Old 04-28-2006, 01:22 PM   #6
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi, Alois! Good to hear from you - I hope all is going well.

ANYWAY:
1. I think the text you cut/pasted was garbled: it is not legal C (or C++) as-is.

2. Here are the errors I got when I tried to compile:
Quote:
gcc -Wall -pedantic -g -o xx xx.c
xx.c: In function `main':
xx.c:8: warning: ISO C forbids nested functions
xx.c:8: error: syntax error before "l"
xx.c:9: error: `count' undeclared (first use in this function)
xx.c:9: error: (Each undeclared identifier is reported only once
xx.c:9: error: for each function it appears in.)
xx.c:11: error: parse error before '}' token
3. I modified it with (guesses) as to what it might have meant, along with explanatory comments:
Code:
#include <stdio.h>

typedef unsigned short uint16;

int
main ()
{
#if TOTALLY_BOGUS_SPACING
  uint16 t l e d s = count e r >> 4 ;
  count e r = (message|>s t r eng th + 60) & 0 x f f ;
#else
  /* Define variables, "counter", "strength" and "message" */
  uint16 counter = 100, strength = 10, message = 0x100;

  /* Variable "tled" takes the left (12?) bits of "counter"
     (and gets rid of the rightmost, least significant 4 bits) */
  uint16 tleds = counter >> 4;

  /* I'd parenthesize more ...  but this code snippet:
     a) adds strength + 60 (here, strength = 70)
     b) OR's the sum against message: 70 | 100 == 102
        ... and ...
     c) AND's the result against 0x100 (102 & 256 == 0) */

  counter = (message | strength + 60) & 0xff;
#endif
  return 0;
}
'Hope that helps .. PSM
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
small syntax problem with C code (implemented in Code Composer Studio) illiniguy3043 Programming 6 01-07-2008 02:14 AM
User Preferences: Use HTML code instead of vB code? (vB code is overrated) stefanlasiewski LQ Suggestions & Feedback 5 07-26-2005 01:37 AM
Editing buttons (quote, code etc.) add the code to the end vharishankar LQ Suggestions & Feedback 2 09-13-2004 09:32 AM
Diffrerence between position independent code and Relocatable code? eshwar_ind Programming 7 05-11-2004 01:40 AM
Open Firmware code for booting OS from SATA : sample code available somewhere ? drsparikh Linux - Hardware 0 03-12-2004 11:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration