Entire SiteAll CommunitiesAVR FreaksAtmel clever ARM-based MCUsInternet the ThingsCapacitive TouchProjectsVendorsWiki


You are watching: Comparison with string literal results in unspecified behavior

\"*\"

I\"m composing my own collection of libraries therefore that basic program writing becomes easier. To make my programs much an ext readable I\"d like to use \"words\" to describe choices which would certainly mean having to compare character strings. I written the following but have been warned:

Warning 1 comparison v string literal outcomes in unspecified habits <-Waddress> C:\\Users\\Simon\\Dropbox\\Electronics\\AVR job templates\\ATMega328\\ATMega328\\timer0.c 24 11 ATMega328

void counter0_mode (char mode<>)if (mode == \"normal\")bit0(TCCR0A, WGM02);bit0(TCCR0A, WGM01);bit0(TCCR0A, WGM00);



Tools, Compilers and General Programming
last Edited: Wed. Jun 17, 2015 - 12:34 pm
height
\"*\"
clawson
\"*\"

Level: Moderator
Joined: Mon. Jul 18, 2005
Posts: 102878 View articles
Location: (using avr-gcc in) Finchingfield, Essex, England
#2
post by clawson: Wed. Jun 17, 2015 - 12:33 afternoon
12345


See more: I Love My Friends Kris Jenner, Kris Jenner I Love My Friends Gifs

Total votes: 0

Until you obtain to C++ I\"m afraid C has actually no == procedure for strings. The library duty to use is dubbed strcmp:

#include void counter0_mode (char mode<>) if (strcmp(mode, \"normal\") == 0) bit0(TCCR0A, WGM02); bit0(TCCR0A, WGM01); bit0(TCCR0A, WGM00); BTW what on earth did you carry out to your code to gain it so bad fomatted? girlfriend do recognize that to write-up code here you press the symbol that looks prefer \"\" ~ above the toolbar that the editor and also then in the pop-up that shows up just post the code replicated from your code editor right into that.

I fairly suspect you have tried to use the old < code > tags system from the old website - that does not work right here (at the moment anyway).

EDIT: PS expected to say .. Why pass about mode<> as a cable anyway. Why not parse the string as soon as you very first receive that then set an enum or something? There\"s no allude having string processing code dotted all about the program favor this - handle any type of human entry strings in one ar when they very first arrive then usage something more \"MCU friendly\" ~ that.