473,320 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

difference between char *key and (char*)&key

I know the first is a pointer to a char type. What does second one means? Thanks
Sep 4 '14 #1
4 1835
weaknessforcats
9,208 Expert Mod 8TB
How is this used in your question?

The & in C++ has different meanings based on how it is used.

Maybe you could post the line of code that troubles you?
Sep 5 '14 #2
while (1)
{
if (SerialKeyPressed((char*)&key)) break;
}

And another question in the mean time relating to the following line of the code:
while ((TIM3->SR1 & TIM3_FLAG_CC1) != TIM3_FLAG_CC1);

What result does (TIM3->SR1 & TIM3_FLAG_CC1) gives - a 1 or 0 and please explain how to understand it.
Sep 5 '14 #3
weaknessforcats
9,208 Expert Mod 8TB
This code:
Expand|Select|Wrap|Line Numbers
  1. while (1)
  2.     {
  3.         if (SerialKeyPressed((char*)&key)) break;
  4.     }
  5.  
is an infinite loop tht will continue until the call to SerialKeyPressed returns true. That is returns something not a zero. key is an argument so &key would be the address of the key. Therefore, (char*)&key tells the compiler to use the address of the key as a char*. I suspect the function needs a char* argument and key is not a char making &key not a char*. Normally, this situation will blow you build but the cast tells the compiler to accept the address against the rules.

(TIM3->SR1 & TIM3_FLAG_CC1) is an expression. Expressions are either true (not 0) or false (0), Here the expression is compared to TIM3_FLAG_CC1. If the expression is not equal to TIM3_FLAG_CC1 you stay in the loop.

TIM3->SR1 & TIM3_FLAG_CC1 uses a bitwise AND. Here you may want to look up bitwise operations to see what this means. In an AND if corresponding bits are true (1) then the AND is true (1). Otherwise, the AND is false. So TIM3->SR1 & TIM3_FLAG_CC will be true if any corresponding true bits (1) in TIM3->SR1 and TIM3_FLAG_C are true. If none of the bits match, the expression is false (0).

101
110
---AND
100 result is true (not 0)
Sep 5 '14 #4
donbock
2,426 Expert 2GB
Are you using C or C++?
How is variable key defined? What is its type?
What is the function prototype of SerialKeyPressed?
Sep 6 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Rathtap | last post by:
I want to use the Identity field (increment 1,1) as a primary key and have a unique constraint on my other field which is of type char. I am worried that related data in other tables may lose...
4
by: Rob Smeets | last post by:
Hi all, I have the following problem: I have to revise a c++ dll. And i'm new to c++. I have to change a function, but i cannot change it's structure. I want to check the parameters and act...
19
by: Rafal Dabrowa | last post by:
What does mean such declaration: void f( char (*ptr) ); Is this the same as void f( char **ptr ); or not ?
5
by: Robert Oschler | last post by:
I am converting a Perl script over to "C" for a potential open source project. I need some open source "C" code that will give me the same functionality of a Perl Style associative array: ...
8
by: Jack Addington | last post by:
I want to scroll through the alphabet in order to scroll some data to the closest name that starts with a letter. If the user hits the H button then it should scroll to the letter closest to H. ...
4
by: active | last post by:
I can use Control.ModifierKeys to determine if a modifying key is pressed when executing MouseDown event, but how can I determine if an "M" was pressed?? Possible? Can't find a clue in...
26
by: the.tarquin | last post by:
Okay, this one has me totally baffled. I have a function, getParsedKey(char* key, char* returnString). I pass in the key I want, it retrieves it from a data structure and puts the value in...
20
by: gert | last post by:
This based on a example i found at http://www.cs.tut.fi/~jkorpela/ forms/cgic.html #include <fcgi_stdio.h> #include <stdlib.h> int urldecode(char *src, char *last, char *dest){ int code;...
7
by: Jan Spatina | last post by:
Hello, I have this type: enum days{sun = 1, mon, tue, wed, thu, fri, sat}; and I have char in which is stored a name of the day: char* day = "wed"; How can I recieve number of the day?
1
by: Anton123456 | last post by:
What i do wrong? Here is my code: #include <graphics.h> #include <stdio.h> #include <conio.h> int main() {
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.